Skip to main content

Additional argparse types and actions.

Project description

About

Additional Python argparse types and actions.

Project homepage: https://github.com/eerimoq/argparse_addons

Installation

$ pip install argparse_addons

Examples

Integer type

The script. See examples/integer.py for the complete script.

parser.add_argument('--min-max',
                    type=argparse_addons.Integer(0, 255))
parser.add_argument('--min',
                    type=argparse_addons.Integer(0, None))
parser.add_argument('--max',
                    type=argparse_addons.Integer(None, 255))
parser.add_argument('--any',
                    type=argparse_addons.Integer())

Error message for the --min-max argument.

$ python3 examples/integer.py --min-max -1
usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY]
integer.py: error: argument --min-max: -1 is not in the range 0..255

Error message for the --min argument.

$ python3 examples/integer.py --min -1
usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY]
integer.py: error: argument --min: -1 is not in the range 0..inf

Error message for the --max argument.

$ python3 examples/integer.py --max 1000
usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY]
integer.py: error: argument --max: 1000 is not in the range -inf..255

Error message for the --any argument.

$ python3 examples/integer.py --any a
usage: integer.py [-h] [--min-max MIN_MAX] [--min MIN] [--max MAX] [--any ANY]
integer.py: error: argument --any: invalid integer value: 'a'

All values within allowed ranges.

$ python3 examples/integer.py --min-max 47 --min 1000 --max -5 --any 1
--min-max: 47
--min:     1000
--max:     -5
--any:     1

Contributing

  1. Fork the repository.

  2. Install prerequisites.

    pip install -r requirements.txt
  3. Implement the new feature or bug fix.

  4. Implement test case(s) to ensure that future changes do not break legacy.

  5. Run the tests.

    make test
  6. Create a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argparse_addons-0.9.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

argparse_addons-0.9.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page