Skip to content

Commit

Permalink
Parse target as an optional positional argument
Browse files Browse the repository at this point in the history
Instead of relying on parsing unknown args add a hidden placeholder positional argument so that target can be passed as a keyword arg, or as the only positional arg
  • Loading branch information
manics committed Nov 20, 2023
1 parent e64907c commit a4cbb04
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions github_activity/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,27 @@
help=("""Whether to include all the GitHub tags"""),
)

# Hidden argument so that target can be optionally passed as a positional argument
parser.add_argument(
"_target",
nargs="?",
default=None,
help=argparse.SUPPRESS,
)


def main():
if not _git_installed_check():
print("git is required to run github-activity", file=sys.stderr)
sys.exit(1)

args, unknown = parser.parse_known_args()
# If we have unknown, it is the target
# TODO: this feels sub-optimal, we should be able to just treat positional args
# as optional.
if unknown and not args.target:
args.target = unknown[0]
args = parser.parse_args()
if args.target and args._target:
raise ValueError(
"target cannot be passed as both a positional and keyword argument"
)
if not args.target:
args.target = args._target

tags = args.tags.split(",") if args.tags is not None else args.tags
# Automatically detect the target from remotes if we haven't had one passed.
Expand Down

0 comments on commit a4cbb04

Please sign in to comment.