-
Notifications
You must be signed in to change notification settings - Fork 150
Description
Description
Have a derive like this:
#[derive(StructOpt)]
struct Opt {
#[structopt(long)]
dry_run: bool,
#[structopt(long)]
config: Option<String>
}automatically produce two command-line flags: --dry-run and --config. Currently, a #[structopt(long = "$NAME")] would have to added to both of them to make them usable.
Have a derive like this:
#[derive(StructOpt)]
enum Cmd {
Loop,
Lutz,
Salchow,
ToeLoop
}automatically produce the subcommands loop, lutz, salchow, and toe-loop. As of #17, a #[structopt(name = "$NAME")] would be required here, otherwise CamelCase names would have to passed on the command line.
Semantics
Let the result of to-kebab-case(id) be id'. It's implemented in https://crates.io/crates/heck
For any field in a derive(StructOpt)'d type, if it does not have a name attribute, the name attribute will default to to-kebab-case($FIELD_NAME). If it does have a long attribute with no value , the long attribute will default to the same thing.
For any enum variant in a derive(StructOpt)'d enum, if it does not have a name attribute, the name attribute will default to to-kebab-case($VARIANT_NAME).
Purpose
To make structopt more convenient to use by reducing the amount of typing needed for common cases. It should not make structopt less intuitive to use.
Concerns
- While convenient, implementing this can mean that a user of
structoptwill have to pass names and flags on the command line that they technically never specified in their source code. Does the convenience outweigh the possible confusion from "magic" code? - The
nameattribute can be easily overridden by a user. However, as far as I can see, there isn't a way to "unset" a.long()call on aclap::Arg. So optional arguments will end up being usable through long flags, even if the user, say, only wants short flags. How common is this scenario? - The default mechanism for lowercasing in
std::charisn't specialised for any given locale. Shouldstructoptsupport customised lowercasing based on locale, or should it remain untailored for simplicity of use?
Alternatives
- Only automatically set the
nameattribute, rather than thelongattribute. This avoids the problem with unremovable long flag names mentioned above. - Don't do anything. Undesirable.
Anything else?