mirror of
https://github.com/ihabunek/toot
synced 2025-02-10 09:00:39 +01:00
Add --json option to instance command
This commit is contained in:
parent
57be6beae8
commit
0c37716de1
@ -1,9 +1,10 @@
|
||||
import re
|
||||
from uuid import uuid4
|
||||
import json
|
||||
import pytest
|
||||
import re
|
||||
|
||||
from toot import api
|
||||
from toot.exceptions import ConsoleError
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
def test_instance(app, run):
|
||||
@ -13,6 +14,14 @@ def test_instance(app, run):
|
||||
assert "running Mastodon" in out
|
||||
|
||||
|
||||
def test_instance_json(app, run):
|
||||
out = run("instance", "--json")
|
||||
data = json.loads(out)
|
||||
assert data["title"] is not None
|
||||
assert data["description"] is not None
|
||||
assert data["version"] is not None
|
||||
|
||||
|
||||
def test_instance_anon(app, run_anon, base_url):
|
||||
out = run_anon("instance", base_url)
|
||||
assert "Mastodon" in out
|
||||
|
@ -40,7 +40,7 @@ def create_app_interactive(base_url):
|
||||
def get_instance_domain(base_url):
|
||||
print_out("Looking up instance info...")
|
||||
|
||||
instance = api.get_instance(base_url)
|
||||
instance = api.get_instance(base_url).json()
|
||||
|
||||
print_out(
|
||||
f"Found instance <blue>{instance['title']}</blue> "
|
||||
|
@ -542,15 +542,19 @@ def instance(app, user, args):
|
||||
raise ConsoleError("Please specify an instance.")
|
||||
|
||||
try:
|
||||
instance = api.get_instance(base_url).json()
|
||||
instance = from_dict(Instance, instance)
|
||||
print_instance(instance)
|
||||
response = api.get_instance(base_url)
|
||||
except ApiError:
|
||||
raise ConsoleError(
|
||||
f"Instance not found at {base_url}.\n"
|
||||
"The given domain probably does not host a Mastodon instance."
|
||||
)
|
||||
|
||||
if args.json:
|
||||
print(response.text)
|
||||
else:
|
||||
instance = from_dict(Instance, response.json())
|
||||
print_instance(instance)
|
||||
|
||||
|
||||
def notifications(app, user, args):
|
||||
if args.clear:
|
||||
|
@ -439,6 +439,7 @@ READ_COMMANDS = [
|
||||
"nargs": "?",
|
||||
}),
|
||||
scheme_arg,
|
||||
json_arg,
|
||||
],
|
||||
require_auth=False,
|
||||
),
|
||||
@ -454,6 +455,7 @@ READ_COMMANDS = [
|
||||
"default": False,
|
||||
"help": "Resolve non-local accounts",
|
||||
}),
|
||||
json_arg,
|
||||
],
|
||||
require_auth=True,
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user