Processing command line arguments might seem like a very simple task (and relative to big problems it is), but there is still a considerable amount of edge cases to cater for. Trust me, I was one of the developers of the Commons CLI library and there was way more work in that than I imagined.

However, more often than not, the command line programs I write, have a very basic argument structure. Libraries like optparse and argparse provide unnecessary features, while processing sys.argv is too brittle, for cases like this.

Kenneth Reitz wrote args a beautiful library to fulfil the needs for command line programs like this.

args can parse this command: program -i infile --output outfile -v=3

import args

infile = args.grouped['-i'][0]
outfile = args.grouped['--output'][0]
verbosity = args.assignments['-v'][0]

and a command that performs an action on a list of PNG files: program *.png

import args

for filepath in args.files:
    # do something with the filepath

Bellissimo!