Skip to content

chbrown/argv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simpler command line argument parsing

In the spirit of optimist: less magic, more flexibility.

pi install argv

Quickstart

Manual specification of arguments, no configuration:

import argv
argv.parse(['-i', 'input.txt', '-z', '--verbose'])
>>> {'i': 'input.txt', 'verbose': True, 'z': True}

Uses sys.argv (without the executable name) if no argument list is given:

import sys
sys.argv
>>> ['/usr/local/bin/bottler', 'exec', 'prog.py', '--debug']
argv.parse()
>>> {'_': ['exec', 'prog.py'], 'debug': True}

Configuration:

parser = argv.Parser()
parser.add('action')
parser.add('target')
parser.add('-d', '--debug')
parser.parse(['exec', 'prog.py', '--debug'])
>>> {'action': 'exec', 'd': True, 'debug': True, 'target': 'prog.py'}

Testing

Continuous integration:

Travis CI Build Status

Or run tests locally:

python setup.py test

Development

Terminology:

  • flag: a command line argument marked with a double dash or each component of a group denoted by a single dash. E.g.,
    • --verbose --logfile logs/app.txt has two flags: verbose and logfile.
    • -czf archive.tgz app/ has three flags: c, z, and f.
  • token: a white-space (or =) separated command line item. E.g.,
    • --input=prog.py --logfile logs/app.txt has four tokens: --input, prog.py, --logfile, and logs/app.txt

Related libraries

TODO: write about differences between this library (argv) and these libraries, relative merits of each, opposing philosophies, etc.

License

Copyright (c) 2013 Christopher Brown. MIT Licensed.

About

Simpler command line argument parsing in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages