[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: mpeterv argparse -- get the last argument
- From: James Darnley <james.darnley@...>
- Date: Thu, 27 Oct 2016 01:55:48 +0200
On 2016-10-26 12:35, Peter Melnichenko wrote:
> Hi James,
>
> On Wed, Oct 26, 2016 at 1:18 AM, James Darnley <james.darnley@gmail.com> wrote:
>> I was trying to use mpeterv's argparse module
>> (https://github.com/mpeterv/argparse) to make a script behave somewhat
>> like `cp` or `mv` in that all arguments except the last one belong to
>> the "input".
>>
>> I tried, what I thought was the obvious:
>>> parser:argument("input"):args("+") -- at least 1 arg
>>> parser:argument("output"):args(1) -- exactly 1 arg
>> but I just get "Error: missing argument 'output'" from it.
>>
>> Is there a way to have the module populate "output" for me? Or should I
>> just do it myself by having the module read them all into "input" and
>> then removing the last one from the table?
>
> argparse matches arguments greedily, so that in your example all arguments
> are considered `input` and then it raises an error as nothing is left for
> `output`. So, indeed, you have to split the last argument manually.
>
> -- Best regards,
> -- Peter Melnichenko
>
Okay. Thank you for your input. I did just that. The help is no
longer as pretty but the script is mostly for my own use.
Attachment:
signature.asc
Description: OpenPGP digital signature