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

Positional argument decorator #225

Merged
merged 9 commits into from
Oct 7, 2015
Merged

Positional argument decorator #225

merged 9 commits into from
Oct 7, 2015

Conversation

henryiii
Copy link
Collaborator

​Adding positional arguments decorator to plumbum.cli. This allows positional or named validators to be added via a decorator on the main function. Default arguments do not go through the validator. For example:

class MyApp(cli.Application):
    @cli.positional(int, float, cli.ExistingFile)
    def main(self, myint, myfloat, *inputs):
        assert isinstance(myint,int)
        ...

This also supports Python 3 notation:

class MyApp(cli.Application):
    def main(self, myint : int, myfloat : float, *inputs : cli.ExistingFile):
        assert isinstance(x,int)
        ...

Also fixed a bug with missing __slots__ in ABC, causing ABC subclasses to be __dict__ classes.

Besides convenience and clarity, especially for variable args, this is going to be important for 1.7.0 if we can get argument completion (since the classic method of manually validating each argument inside main is not introspectable). I have not changed the help output, but that is another future possibility.

Closes #200 (my own request)

@henryiii henryiii changed the title Nohup Positional argument decorator Sep 21, 2015
@henryiii henryiii mentioned this pull request Sep 21, 2015
5 tasks
@henryiii henryiii added this to the v1.6.0 milestone Sep 21, 2015
@henryiii henryiii assigned henryiii and unassigned henryiii Sep 21, 2015
tomerfiliba added a commit that referenced this pull request Oct 7, 2015
Positional argument decorator
@tomerfiliba tomerfiliba merged commit 5b7e02b into master Oct 7, 2015
@henryiii henryiii deleted the nohup branch October 8, 2015 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Validator on main args
2 participants