[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: mpeterv argparse -- get the last argument
- From: Peter Melnichenko <mpeterval@...>
- Date: Wed, 26 Oct 2016 13:35:10 +0300
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