Add --json option to whoami command
This commit is contained in:
parent
6cdba16fcf
commit
2c4f7e17c9
3 changed files with 22 additions and 3 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from toot.entities import Account, from_dict
|
||||||
|
|
||||||
|
|
||||||
def test_whoami(user, run):
|
def test_whoami(user, run):
|
||||||
|
@ -6,6 +9,12 @@ def test_whoami(user, run):
|
||||||
assert f"@{user.username}" in out
|
assert f"@{user.username}" in out
|
||||||
|
|
||||||
|
|
||||||
|
def test_whoami_json(user, run):
|
||||||
|
out = run("whoami", "--json")
|
||||||
|
account = from_dict(Account, json.loads(out))
|
||||||
|
assert account.username == user.username
|
||||||
|
|
||||||
|
|
||||||
def test_whois(app, friend, run):
|
def test_whois(app, friend, run):
|
||||||
variants = [
|
variants = [
|
||||||
friend.username,
|
friend.username,
|
||||||
|
|
|
@ -516,8 +516,12 @@ def blocked(app, user, args):
|
||||||
|
|
||||||
|
|
||||||
def whoami(app, user, args):
|
def whoami(app, user, args):
|
||||||
account = api.verify_credentials(app, user).json()
|
response = api.verify_credentials(app, user)
|
||||||
print_account(account)
|
if args.json:
|
||||||
|
print(response.text)
|
||||||
|
else:
|
||||||
|
account = response.json()
|
||||||
|
print_account(account)
|
||||||
|
|
||||||
|
|
||||||
def whois(app, user, args):
|
def whois(app, user, args):
|
||||||
|
|
|
@ -232,6 +232,12 @@ tag_arg = (["tag_name"], {
|
||||||
"help": "tag name, e.g. Caturday, or \"#Caturday\"",
|
"help": "tag name, e.g. Caturday, or \"#Caturday\"",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
json_arg = (["--json"], {
|
||||||
|
"action": "store_true",
|
||||||
|
"default": False,
|
||||||
|
"help": "print json instead of plaintext",
|
||||||
|
})
|
||||||
|
|
||||||
# Arguments for selecting a timeline (see `toot.commands.get_timeline_generator`)
|
# Arguments for selecting a timeline (see `toot.commands.get_timeline_generator`)
|
||||||
common_timeline_args = [
|
common_timeline_args = [
|
||||||
(["-p", "--public"], {
|
(["-p", "--public"], {
|
||||||
|
@ -388,7 +394,7 @@ READ_COMMANDS = [
|
||||||
Command(
|
Command(
|
||||||
name="whoami",
|
name="whoami",
|
||||||
description="Display logged in user details",
|
description="Display logged in user details",
|
||||||
arguments=[],
|
arguments=[json_arg],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
|
|
Loading…
Reference in a new issue