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

Allow custom arg validations #170

Closed
kbknapp opened this issue Jul 30, 2015 · 0 comments
Closed

Allow custom arg validations #170

kbknapp opened this issue Jul 30, 2015 · 0 comments
Labels
A-parsing Area: Parser's logic and needs it changed somehow.

Comments

@kbknapp
Copy link
Member

kbknapp commented Jul 30, 2015

One should be allowed to specify a custom validation function which will be run against an argument value.

From a birds eye view:

let app = App::new("test")
              .arg(Arg::with_name("opt")
                     .long("long")
                     .takes_value(true)
                     .validator(|val| { 
                         if val.len() == 5 { 
                             Ok(val) 
                         } else { 
                             Err("--long must be 5 characters long") 
                         }
                     })
               );  

If possible I may also look at providing some pre-conceived validator functions which would could be used like so:

let app = App::new("test")
              .arg(Arg::with_name("opt")
                     .long("long")
                     .takes_value(true)
                     .validator( ArgValidators::U8 )
               );  
@kbknapp kbknapp added T: new feature A-parsing Area: Parser's logic and needs it changed somehow. labels Jul 30, 2015
kbknapp added a commit that referenced this issue Aug 14, 2015
Custom validations can now be performed on the argument values that are
fatal when the tests fail.

Closes #170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow.
Projects
None yet
Development

No branches or pull requests

1 participant