Skip to content

Additional parameter to validator function #1913

Answered by kbknapp
psychonaut asked this question in Q&A
Discussion options

You must be logged in to vote

In #1206 we discussed almost exactly this. Although the linked issue isn't strictly about this feature, it came up because it relates to what you're asking about. The idea for some kind of Map or Handler on an argument is the relevant comments. We haven't come to any consensus about that feature yet, so I'm not sure what direction we're going to take, if any, yet.

For now, best practice is if your validator requires knowledge of other arguments it should be done after parsing completes in consumer code.

i.e.

fn valid_answers(m: &ArgMatches) -> Result<(), String> {
    // ... validate your args
}

To the user of your binary it should feel effectively the same.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by kbknapp
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants