1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-06-23 06:25:26 +00:00

Move common auth commands to a variable

This commit is contained in:
Ivan Habunek 2018-06-30 09:44:36 +02:00
parent c2af5a879c
commit 9c4964116e
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -24,6 +24,7 @@ def visibility(value):
Command = namedtuple("Command", ["name", "description", "require_auth", "arguments"])
# Aruguments added to every command
common_args = [
(["--no-color"], {
"help": "don't use ANSI colors in output",
@ -39,7 +40,14 @@ common_args = [
"help": "show debug log in console",
"action": 'store_true',
"default": False,
})
}),
]
# Arguments added to commands which require authentication
common_auth_args = [
(["-u", "--using"], {
"help": "the account to use, overrides active account",
}),
]
account_arg = (["account"], {
@ -328,12 +336,12 @@ def get_argument_parser(name, command):
description=command.description,
epilog=CLIENT_WEBSITE)
for args, kwargs in command.arguments + common_args:
parser.add_argument(*args, **kwargs)
# If the command requires auth, give an option to select account
combined_args = command.arguments + common_args
if command.require_auth:
parser.add_argument("-u", "--using", help="the account to use, overrides active account")
combined_args += common_auth_args
for args, kwargs in combined_args:
parser.add_argument(*args, **kwargs)
return parser