-
I have this subcommand: use clap::{builder::ValueParser, Arg, Command};
pub fn validator_user() -> ValueParser {
ValueParser::from(move |s: &str| -> std::result::Result<String, String> {
if s != "new" {
Ok(s.to_owned())
} else {
Err("Invalid user".to_owned())
}
})
}
pub fn subcommand_fingerprint() -> Command {
Command::new("fingerprint")
.about("Print the fingerprint of a public ssh key")
.visible_alias("f")
.arg(
Arg::new("key")
.short('k')
.long("key")
.help("Path to public ssh key or index when using option -u"),
)
.arg(
Arg::new("user")
.short('u')
.long("user")
.help("GitHub username or URL, optional [-k N] where N is the key index")
.value_parser(validator_user()),
)
} But how to test the |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Nov 14, 2023
Replies: 1 comment
-
Some options
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nbari
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some options
Command::try_get_matches_from
and pass in different combinations and verify the resultValueParser
toimpl TypedValueParser
and write tests againstTypedValueParser::parse