.. blargs documentation master file, created by sphinx-quickstart on Sat Dec 31 12:11:21 2011. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to blargs's documentation! ================================== .. image:: logo_large.png :align: right blargs provides easy command line parsing, as an alternative to argparse and optparse from Python's standard library. The main distinctions are: * Cleaner, more minimal, and possibly more `pythonic` syntax. * Support for arbitrarily complex dependency relationships. For example, argument A might require arguments B and C, while conflicting with D; or requiring argument E in the case that A is less than 10 or B is equal to the string 'wonderful!'. * Emphasis on `ease of use` over `configurability`. Blargs has been tested on Python2.6 to Python3.2 and PyPy. Note: blargs is currently still in *beta*. You can help by submitting bugs here_! .. _here: https://bitbucket.org/gyllstromk/blargs/issues?status=new&status=open Installation ============ By Pip: :: pip install blargs Or by git: :: git clone https://bitbucket.org/gyllstromk/blargs.git License ======= BSD .. One big example .. =============== .. >>> with Parser(locals()) as p: # create argument parser, storing values to locals() .. ... p.float('salary').shorthand('s').required() .. ... p.str('nickname').default('No nickname') .. ... age = p.int('age').shorthand('a').required() .. ... p.str('parent_name').if_(age < 18) Quick start =========== The preferred use of :class:`Parser` is via the ``with`` idiom, as follows: >>> with Parser(locals()) as p: ... p.int('arg1') ... p.str('arg2') ... p.flag('arg3') ... >>> print 'Out of with statement; sys.argv is now parsed!' >>> print arg1, arg2, arg3 Note the use of ``locals`` is limited to the global scope; use a dictionary otherwise, getting argument values using the argument names as keys. The user can now specify the following command lines: :: python test.py --arg1=3 # either '=' ... python test.py --arg1 3 # ...or space is allowed python test.py --arg2 'hello' # python test.py --arg3 # no value is specified; implied true .. When the with clause loses scope, the ``sys.argv`` is parsed. In the case above, .. two arguments are specified: ``arg1``, which accepts an int; ``arg2``, which .. accepts a str, and ``arg3``, which is a flag argument (i.e., it is specified or .. ommitted). .. The following command lines will be rejected: :: python test.py --arg1 # no value specified for 'arg1' python test.py --arg1 a # 'a' does not parse to int python test.py --arg3 a # 'arg3' is a flag and does not accept a value Additionally, users can query for help: :: python test.py --help To which the program will respond: :: Arguments: --arg1 --arg2