args

by kennethreitz-archive

kennethreitz-archive / args

Argument Parsing for Humans™

207 Stars 21 Forks Last release: Not found BSD 2-Clause "Simplified" License 41 Commits 1 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

args

Argument Parsing for Humans.

Usage

Here's an example application::

import args

print 'Arguments passed in: ' + str(args.all) print 'Flags detected: ' + str(args.flags) print 'Files detected: ' + str(args.files) print 'NOT files detected: ' + str(args.not_files) print 'Grouped Arguments: ' + str(args.grouped) print 'Assignments detected: ' + str(args.assignments)

No arguments::

$ tool
Arguments passed in: []
Flags detected: 
Files detected: []
NOT files detected: 
Grouped Arguments: OrderedDict([('_', )])
Assignments detected: OrderedDict()

A few arguments::

$ tool -s yes no --number=one --letter a b c --number=two
Arguments passed in: ['-s', 'yes', 'no', '--number=one', '--letter', 'a', 'b', 'c', '--number=two']
Flags detected: 
Files detected: []
NOT files detected: 
Grouped Arguments: OrderedDict([('_', ), ('-s', ), ('--number=one', ), ('--letter', ), ('--number=two', )])
Assignments detected: OrderedDict([('--number', )])

A few expanded file arguments::

$ tool *.py
Arguments passed in: ['args.py', 'setup.py', 'tests.py']
Flags detected: 
Files detected: ['args.py', 'setup.py', 'tests.py']
NOT files detected: 
Grouped Arguments: OrderedDict([('_', )])
Assignments detected: OrderedDict()

A few non-expanded file arguments::

$ tool '*.py'
Arguments passed in: ['*.py']
Flags detected: 
Files detected: ['args.py', 'setup.py', 'tests.py']
NOT files detected: 
Grouped Arguments: OrderedDict([('_', )])
Assignments detected: OrderedDict()

A few mixed files/flags/arguments::

Arguments passed in: ['*.py', '--letter', 'a', 'b', 'c', '-s', '/home/example/.example', '--number=one', '--number=two']
Flags detected: 
Files detected: ['setup.py', 'args.py', 'tool.py', 'tests.py', '/home/example/.example/two', '/home/example/.example/one']
NOT files detected: 
Grouped Arguments: OrderedDict([('_', ), ('--letter', ), ('-s', ), ('--number=one', ), ('--number=two', )])
Assignments detected: OrderedDict([('--number', )])

Installation

Installation is simple with pip::

$ pip install args

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.