Multiple boolean flags #5287
Answered
by
epage
forest1102
asked this question in
Q&A
Multiple boolean flags
#5287
-
Hello, I am developing a new feature in diesel. use clap::ArgGroup;
use clap::ArgAction;
use clap::Arg;
use clap::Command;
fn main(){
let m = Command::new("generate")
.arg(
Arg::new("table-name")
.index(1)
.num_args(1..)
.action(clap::ArgAction::Append)
.help("Table names to filter."),
)
.arg(
Arg::new("only-tables")
.short('o')
.long("only-tables")
.action(ArgAction::SetTrue)
.help("Only include tables from table-name that matches regexp.")
,
)
.arg(
Arg::new("except-tables")
.short('e')
.long("except-tables")
.action(ArgAction::SetTrue)
.help("Exclude tables from table-name that matches regex.")
,
)
.arg(
Arg::new("print-schema-key")
.long("print-schema-key")
.action(clap::ArgAction::Append)
.help("select schema key from diesel.toml, use 'default' for print_schema without key."),
)
.group(ArgGroup::new("filter").args(["only-tables", "except-tables"]).multiple(true))
.get_matches_from(vec![
"generate", "--print-schema-key", "user1", "table1", "-o", "--print-schema-key", "user2", "table2", "-o"
]);
dbg!(m.try_get_many::<bool>("only-tables").unwrap().map(|v| v.collect::<Vec<_>>()));
} |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Jan 8, 2024
Replies: 1 comment 3 replies
-
What are you trying to accomplish with For example:
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, so you are looking to do something like #1704. #2222 might be a future way of making this simple.
https://docs.rs/clap/latest/clap/_derive/_cookbook/find/index.html is the closest example we have. It had some bugs but 4.4.14 fixed them. Be sure to depend on 4.4.14 and look at that version in the docs.