Pyopt - an attempt at a pythonic optparse
I put some sweat into this one so I was hoping to see if you guys like it or have any ideas for improvement. http://code.google.com/p/pyopt/ Currently there are 2 modes of operation, 1. keyword command-line functions which create switches (-m, -r etc). 2. positional command-line functions which simply translate positional arguments from the command-line to a function. possibly in the future I'll implement a mixed keyword/positional arguments behaviour. At the moment annotations are mandatory for explicitness and here's an example usage: from pyopt import CmdPos from pyopt import parse_cmds @CmdPos def possy(archer:str, boulder:float, magic:int=42): """Shows an example positional command-line function. archer - is a str boulder - should be a float magic - a number that is magical""" print(repr(archer), repr(boulder), repr(magic)) if __name__ == "__main__": parse_cmds() Notice 4 things: * an import * a decorator * a parse_cmds() * type-annotations for casting The following functionality is exposed: C:\>example.py -h Usage: example.py archer boulder [magic] Shows an example positional command-line function. archer - is a str boulder - should be a float magic - a number that is magical C:\>example.py 1 2 3 '1' 2.0 3 C:\>example.py 1 2 '1' 2.0 42 C:\>example.py 13 2 arguments required, got only 1. Run with ? or -h for more help.
participants (10)
-
Antoine Pitrou
-
Ben Finney
-
Eric Smith
-
Greg Ewing
-
Nick Coghlan
-
RunThePun
-
Sean Reifschneider
-
Steven D'Aprano
-
Tennessee Leeuwenburg
-
Yuvgoog Greenle