You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm following the git-derive example and got all my commands/subcommands working. I have added some options at the top level successfully but I cannot figure out how to pull out the arguments from this.
Sample:
use clap::{Command, arg};fncli() -> Command{Command::new("mm_tools").about("Command line tools for Mattermost").subcommand_required(true).arg_required_else_help(true).allow_external_subcommands(true).subcommand(Command::new("get").args_conflicts_with_subcommands(true).flatten_help(true).subcommand(Command::new("teams")).subcommand(Command::new("playbooks")),).subcommand(Command::new("run").args_conflicts_with_subcommands(true).flatten_help(true).args(push_args()).subcommand(Command::new("playbook").arg(arg!([PLAYBOOK]))),).args([arg!(-c --config <CONFIG> "Optionally set a config to use"),arg!(-d --debug "Turns on debugging information"),])}fnpush_args() -> Vec<clap::Arg>{vec![arg!(-b --book <PLAYBOOK>)]}fnmain(){let matches = cli().get_matches();match matches.subcommand(){Some(("get", sub_matches)) => {let get_command = sub_matches.subcommand().unwrap_or(("teams", sub_matches));match get_command {("teams", sub_matches) => {println!("Get Teams")}("playbooks", sub_matches) => {println!("Get Playbooks")}(&_, _) => unreachable!(),}}Some(("run", sub_matches)) => {let run_command = sub_matches.subcommand().unwrap_or(("teams", sub_matches));match run_command {("playbooks", sub_matches) => {println!("Run Playbooks")}(&_, _) => unreachable!(),}}
_ => unreachable!(),}}
Cargo.toml
[package]
name = "mm_tools"version = "0.1.0"edition = "2021"authors = ["Jon Nials"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
mattermost_api = { version = "0.3.0" }
[dependencies.clap]
version = "4.5.4"features = ["color", "derive", "help", "usage", "string", "wrap_help", "env", "suggestions"]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm following the
git-derive
example and got all my commands/subcommands working. I have added some options at the top level successfully but I cannot figure out how to pull out the arguments from this.Sample:
Cargo.toml
Beta Was this translation helpful? Give feedback.
All reactions