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