Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse target as an optional positional argument #94

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading