Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Adds krux.argparse standard library for CLI args. #50

Closed
wants to merge 3 commits into from

Conversation

plathrop-sfdc
Copy link
Contributor

Adds krux.argparse for argparse utilities/extensions; the first of these
is AppendOverDefault, which is an argparse Action class that behaves
similar to action='append' but over-writes the default if an option is
specified on the CLI.

Adds krux.argparse for argparse utilities/extensions; the first of these
is AppendOverDefault, which is an argparse Action class that behaves
similar to `action='append'` but over-writes the default if an option is
specified on the CLI.
krux/argparse.py Outdated
['1.2.3.4', '5.6.7.8']
"""
def __call__(self, parser, namespace, values, option_string=None):
if namespace.ips == self.default:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this action going to be used only for ip addresses? the naming here suggests that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urgh. No, good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6f45f7e

@hanpeter
Copy link
Contributor

You can create a new class for this, or you can just use nargs='*' for this.

This argument should do what you are looking for:

group.add_argument(
    '--test',
    type=str,
    default=['127.0.0.1'],
    nargs='*',
)

@plathrop-sfdc
Copy link
Contributor Author

@hanpeter that's... really non-obvious.

But thanks, I guess! Closing.

@plathrop-sfdc plathrop-sfdc deleted the plathrop/EPE-859-argparse-util branch April 18, 2017 15:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants