Re: argparse limitations

2012-07-31 Thread Benoist Laurent
> The standard way, however, is to have a parser that takes the first > non-option argument as a subcommand name and parses the remaining arguments > according to that subcommand. Your command line users are more likely to be > able to understand how to use the program if it works that way. I'l

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 13:51, Benoist Laurent wrote: > > Le Jul 31, 2012 à 1:45 PM, Oscar Benjamin a écrit : > > > > On 31 July 2012 12:03, Benoist Laurent wrote: > >> Finally. >> >> The code I proposed doesn't work in this case: if you add any positional >> argument to one of the subparsers, then the

Re: argparse limitations

2012-07-31 Thread Benoist Laurent
Le Jul 31, 2012 à 1:45 PM, Oscar Benjamin a écrit : > > > On 31 July 2012 12:03, Benoist Laurent wrote: > Finally. > > The code I proposed doesn't work in this case: if you add any positional > argument to one of the subparsers, then the parsing doesn't work anymore. > The reason seems to be

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 12:03, Benoist Laurent wrote: > Finally. > > The code I proposed doesn't work in this case: if you add any positional > argument to one of the subparsers, then the parsing doesn't work anymore. > The reason seems to be that argparse thinks the last argument of the first > parser i

Re: argparse limitations

2012-07-31 Thread Benoist Laurent
Finally. The code I proposed doesn't work in this case: if you add any positional argument to one of the subparsers, then the parsing doesn't work anymore. The reason seems to be that argparse thinks the last argument of the first parser is the last but one argument. Hence, if a subparser takes

Re: argparse limitations

2012-07-31 Thread Benoist Laurent
Really sorry about that. So, for the community, below is the full code for a tool that behaves like a Unix standard tool. It takes in argument the files to process and a command. """Just to setup a command-line parser that acts just like a unix standard tool.""" import argparse import sys def

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On Jul 31, 2012 10:32 AM, "Benoist Laurent" wrote: > > Well sorry about that but it seems I was wrong. > It was Friday evening and I guess I've not been careful. > > Actually when you specify nargs="?", the doc says "One argument will be consumed from the command line if possible, and produced as

Re: argparse limitations

2012-07-31 Thread Benoist Laurent
Well sorry about that but it seems I was wrong. It was Friday evening and I guess I've not been careful. Actually when you specify nargs="?", the doc says "One argument will be consumed from the command line if possible, and produced as a single item". So you can't pass several arguments to the

Re: argparse limitations

2012-07-27 Thread Benoist Laurent
Yes basically looks like you get it. I have to further test it but my first impression is that it's correct. So actually the point was to use nargs="?". Thank you very much. Ben Le Jul 27, 2012 à 5:44 PM, Peter Otten a écrit : > Benoist Laurent wrote: > >> I'm impletting a tool in Python.

Re: argparse limitations

2012-07-27 Thread Ian Kelly
On Fri, Jul 27, 2012 at 10:26 AM, Ian Kelly wrote: > It may be a bit awkward having to type "-i" once per file in the > command line, but it does clear up the ambiguity. Or you could bite the bullet and make the input files argument part of the subparser, which you may find ugly, but I believe it

Re: argparse limitations

2012-07-27 Thread Ian Kelly
On Fri, Jul 27, 2012 at 9:19 AM, Benoist Laurent wrote: > That's the solution I came to. > But I'm not very happy with this since I can definitively not make my > program act as a standard unix tool. > Any other solution? I don't understand; that's pretty much the same way that standard unix tool

Re: argparse limitations

2012-07-27 Thread Peter Otten
Benoist Laurent wrote: > I'm impletting a tool in Python. > I'd like this tool to behave like a standard unix tool, as grep for > exemple. I chose to use the argparse module to parse the command line and > I think I'm getting into several limitations of this module. > >> First Question. > How can

Re: argparse limitations

2012-07-27 Thread Benoist Laurent
Le Jul 27, 2012 à 4:43 PM, Oscar Benjamin a écrit : > > > On 27 July 2012 15:26, Benoist Laurent wrote: > Hi, > > I'm impletting a tool in Python. > I'd like this tool to behave like a standard unix tool, as grep for exemple. > I chose to use the argparse module to parse the command line and

Re: argparse limitations

2012-07-27 Thread Oscar Benjamin
On 27 July 2012 15:26, Benoist Laurent wrote: > Hi, > > I'm impletting a tool in Python. > I'd like this tool to behave like a standard unix tool, as grep for > exemple. > I chose to use the argparse module to parse the command line and I think > I'm getting into several limitations of this modul

argparse limitations

2012-07-27 Thread Benoist Laurent
Hi, I'm impletting a tool in Python. I'd like this tool to behave like a standard unix tool, as grep for exemple. I chose to use the argparse module to parse the command line and I think I'm getting into several limitations of this module. > First Question. How can I configure the the ArgumentPa