Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required variable positional arguments #59

Open
treyhunner opened this issue Oct 5, 2016 · 1 comment
Open

Required variable positional arguments #59

treyhunner opened this issue Oct 5, 2016 · 1 comment

Comments

@treyhunner
Copy link

It would be convenient if I can specify that given *args are required.

Here I'm able to convert all captured *numbers to float, but I cannot find a way to require numbers to be non-empty.

I'm using a SystemExit exception as a workaround, but if begins printed out an error and the usage statement for me, that would be much more convenient.

I often require at least one positional argument when using *args so this is a common use case for me.

import begin

@begin.start
@begin.convert(numbers=float)
def main(*numbers : "numbers to add"):
    """Add the given numbers"""
    if numbers:
        print(sum(numbers)
    else:
        raise SystemExit("No numbers to add!")
@Lapin0t
Copy link

Lapin0t commented Dec 13, 2016

What you are saying is that it would be nice to have finer specification of nargs argument to argparse's add_argument. Maybe it could be done with something like @begin.params(numbers={'nargs':'+'}). Maybe having a lot of chained decorators is not so cool so @begin.convert could be included in @begin.params(numbers={'type':float, 'nargs':'+'}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants