-
Notifications
You must be signed in to change notification settings - Fork 128
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
Allow repeating an option that takes multiple values #1445
Conversation
Thanks for updating the behavior across all commands @victorlin! I believe there are also options that use double-quotes for nargs, i.e. |
114e21b
to
3a758f1
Compare
@joverlee521 good catch, updated in force-push and now some CI tests are failing. Taking a look now |
I think the fix is d0d0bf0 applied everywhere |
5fa320c
to
4a25d3b
Compare
4a25d3b
to
2020618
Compare
From PEP 8 recommendations: Comparisons to singletons like None should always be done with is or is not, never the equality operators. <https://peps.python.org/pep-0008/#programming-recommendations>
e1fbbfc
to
3a5a6bf
Compare
3a5a6bf
to
e76e9ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed by inspection (did not test), and this looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good by inspection!
One final note that there are options that use nargs="*"
that should probably also use action=extend
.
Many command line arguments take multiple values. Previously, to utilize this feature, all values must be specified after a single option flag (e.g. --exclude-where 'region=A' 'region=B'). If options were set using separate option flags (e.g. --exclude-where 'region=A' --exclude-where 'region=B'), only the last flag would be used, which is unintuitive. This commit enables all option flags to be used. Done across the codebase by adding action='extend' to all options that use nargs='+' or '*' and did not already specify an action. A side effect of action='extend' is that it extends instead of replacing a default value defined in add_argument. For arguments that use a custom default value, use a custom argparse action ExtendOverwriteDefault, based on the similarly named AppendOverwriteDefault from Nextstrain CLI¹. ¹ <https://github.com/nextstrain/cli/blob/9bf646b0c795d04658a6f6807d74428b7c173995/nextstrain/cli/argparse.py#L183-L197>
e76e9ef
to
4ddef23
Compare
@joverlee521 good catch, included |
Description of proposed changes
Many command line arguments take multiple values. Previously, to utilize this feature, all values must be specified after a single option flag (e.g.
--exclude-where 'region=A' 'region=B'
). If options were set using separate option flags (e.g.--exclude-where 'region=A' --exclude-where 'region=B'
), only the last flag would be used, which is unintuitive. This commit enables all option flags to be used.Done across the codebase by adding
action='extend'
to all options that usenargs='+'
and did not already specify an action.A side effect of
action='extend'
is that it extends instead of replacing a default value defined inadd_argument
. Allow users to continue overriding the default value by first defaulting to an empty list constant, then setting the intended default value later during argument validation.Related issue(s)
Checklist
DEFER_LIST_DEFAULT