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
First, just let me thank you for this amazing library 😄. It really is amazing.
I'm not sure whether this is caused by structopt or by clap, but I'm posting it here since this is what I use.
I created main.rs based on one of the examples in the docs:
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct MakeCookie {
#[structopt(name = "supervisor", default_value = "Puck", long = "supervisor")]
supervising_faerie: String,
/// The faerie tree this cookie is being made in.
tree: Option<String>,
#[structopt(subcommand)] // Note that we mark a field as a subcommand
cmd: Command,
}
#[derive(StructOpt, Debug)]
enum Command {
/// Pound acorns into flour for cookie dough.
Pound {
acorns: u32,
},
/// Add magical sparkles -- the secret ingredient!
Sparkle {
#[structopt(short, parse(from_occurrences))]
magicality: u64,
#[structopt(short)]
color: String,
},
Finish(Finish),
}
// Subcommand can also be externalized by using a 1-uple enum variant
#[derive(StructOpt, Debug)]
struct Finish {
#[structopt(short)]
time: u32,
#[structopt(subcommand)] // Note that we mark a field as a subcommand
finish_type: FinishType,
}
// subsubcommand!
#[derive(StructOpt, Debug)]
enum FinishType {
Glaze {
applications: u32,
},
Powder {
flavor: String,
dips: u32,
}
}
fn main() {
let app = MakeCookie::from_args();
println!("{:?}", app);
}
Running this example without providing subcommand does result in an error but does not print any error:
~\Code\tmp\rust-cmd master ❯ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
~\Code\tmp\rust-cmd master ❯ .\target\debug\rust-cmd.exe -h
rust-cmd 0.1.0
USAGE:
rust-cmd.exe [OPTIONS] [tree] <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--supervisor <supervisor> [default: Puck]
ARGS:
<tree> The faerie tree this cookie is being made in
SUBCOMMANDS:
finish
help Prints this message or the help of the given subcommand(s)
pound Pound acorns into flour for cookie dough
sparkle Add magical sparkles -- the secret ingredient!
~\Code\tmp\rust-cmd master ❯ .\target\debug\rust-cmd.exe tree
rust-cmd 0.1.0
USAGE:
rust-cmd.exe [OPTIONS] [tree] <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--supervisor <supervisor> [default: Puck]
ARGS:
<tree> The faerie tree this cookie is being made in
SUBCOMMANDS:
finish
help Prints this message or the help of the given subcommand(s)
pound Pound acorns into flour for cookie dough
sparkle Add magical sparkles -- the secret ingredient!
~\Code\tmp\rust-cmd master ❯ echo $?
False
If I'm missing a regular positional argument it does prints the error:
~\Code\tmp\rust-cmd master ❯ .\target\debug\rust-cmd.exe pound
error: The following required arguments were not provided:
<acorns>
USAGE:
rust-cmd.exe pound <acorns>
For more information try --help
This is because structopt (and clap_derive which is a fork of structopt) use SubcommandRequiredElseHelp. This makes it so its both an error and a shortcut to show help.
First, just let me thank you for this amazing library 😄. It really is amazing.
I'm not sure whether this is caused by structopt or by clap, but I'm posting it here since this is what I use.
I created
main.rs
based on one of the examples in the docs:Running this example without providing subcommand does result in an error but does not print any error:
If I'm missing a regular positional argument it does prints the error:
Is this a normal behavior?
Versions:
rustc 1.56.1 (59eed8a2a 2021-11-01)
structopt v0.3.25
Thanks
Haim
The text was updated successfully, but these errors were encountered: