Skip to content

Commit

Permalink
Move common auth commands to a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Dec 30, 2018
1 parent c2af5a8 commit 9c49641
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -39,7 +40,14 @@ def visibility(value):
"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"], {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9c49641

Please sign in to comment.