Re: argparse and subparsers

2016-06-28 Thread Michele Simionato
I did not know about docopt. It is basically the same idea of this recipe I wrote about 12 years ago: https://code.activestate.com/recipes/278844-parsing-the-command-line/?in=user-1122360 Good that it was reinvented :-) -- https://mail.python.org/mailman/listinfo/python-list

RE: argparse and subparsers

2016-06-27 Thread Joseph L. Casale
> Not sure if this fits the bill, or makes sense here, but I came cross > "docopt" which touts itself as a "Command-line interface description > language". I used it in a project and it seems to be pretty easy to use > as well as elegant. It stores the arguments & values as a dictionary, > keyed by

Re: argparse and subparsers

2016-06-27 Thread Sachin Garg
On Monday 27 June 2016 06:28 AM, Steven D'Aprano wrote: > On Monday 27 June 2016 15:34, Lawrence D’Oliveiro wrote: > >> On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: >> >>> # Set verbose flag >>> verbose = False >>> if arguments['--verbose']: >>> verbose = True >>> elif arg

Re: argparse and subparsers

2016-06-27 Thread Steven D'Aprano
On Monday 27 June 2016 15:34, Lawrence D’Oliveiro wrote: > On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: > >> # Set verbose flag >> verbose = False >> if arguments['--verbose']: >> verbose = True >> elif arguments['-q']: >> verbose = False > > Don’t you just love code

Re: argparse and subparsers

2016-06-26 Thread Lawrence D’Oliveiro
On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: > # Set verbose flag > verbose = False > if arguments['--verbose']: > verbose = True > elif arguments['-q']: > verbose = False Don’t you just love code (and commenting) like this... -- https://mail.python.org/mailman/listi

Re: argparse and subparsers

2016-06-26 Thread Sachin Garg
On Sunday 26 June 2016 02:51 PM, Joseph L. Casale wrote: > I have some code where sys.argv is sliced up and manually fed to discrete > argparse > instances each with a single subparser. The reason the discrete parsers all > having a > single subparser was to make handling the input simpler, the f

Re: argparse and subparsers

2016-06-26 Thread Lawrence D’Oliveiro
On Monday, June 27, 2016 at 6:56:41 AM UTC+12, Joseph L. Casale wrote: > This has become unmaintainable as the manual slicing is always subject > to a new case by where a parser has a positional, switch or optional > parameter for example. Also, since argv is grouped by subparser > specifiers, if a

argparse and subparsers

2016-06-26 Thread Joseph L. Casale
I have some code where sys.argv is sliced up and manually fed to discrete argparse instances each with a single subparser. The reason the discrete parsers all having a single subparser was to make handling the input simpler, the first arg in the slice could be left in. This has become unmaintai