Closed EverlastingBugstopper closed 4 years ago
maybe https://docs.rs/clap/2.33.3/clap/struct.Arg.html#method.global ?
#[derive(Debug, StructOpt)]
pub struct MyApp {
#[structopt(long = "log", short, global = true)]
pub log_level: tracing_core::Level,
#[structopt(subcommand)]
command: Command,
}
that works perfectly!!!! thanks :smile:
from
structopt
docs:this sounds perfect!! except... the example that follows doesn't particularly describe what i'd expect it to.
i have an app that is built up with subcommands:
What I want to do is to add an argument that can be accepted by any subcommand that alters the log level of the entire app, so my instinct was to just add that field to the
MyApp
struct at the top level.With this setup, I'd expect to be able to run a command like this:
cargo run -- run set 5 --log debug
orcargo run -- run clear --log warn
, but when I do that, I geterror: Found argument '--log' which wasn't expected, or isn't valid in this context
It works just fine if I put the
--log
at the very front, like this:cargo run -- --log debug run set 5
orcargo run -- --log warn run clear
, but... that's not really how I want users to have to specify the argument. Any ideas are super appreciated!