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
structopt will 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
name attribute 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 a clap::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::char isn't specialised for any given locale. Should structopt support customised lowercasing based on locale, or should it remain untailored for simplicity of use?
Alternatives
- Only automatically set the
name attribute, rather than the long attribute. This avoids the problem with unremovable long flag names mentioned above.
- Don't do anything. Undesirable.
Anything else?
Description
Have a derive like this:
automatically produce two command-line flags:
--dry-runand--config. Currently, a#[structopt(long = "$NAME")]would have to added to both of them to make them usable.Have a derive like this:
automatically produce the subcommands
loop,lutz,salchow, andtoe-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)beid'. It's implemented in https://crates.io/crates/heckFor any field in a
derive(StructOpt)'d type, if it does not have anameattribute, thenameattribute will default toto-kebab-case($FIELD_NAME). If it does have alongattribute with no value , thelongattribute will default to the same thing.For any enum variant in a
derive(StructOpt)'d enum, if it does not have anameattribute, thenameattribute will default toto-kebab-case($VARIANT_NAME).Purpose
To make
structoptmore convenient to use by reducing the amount of typing needed for common cases. It should not makestructoptless intuitive to use.Concerns
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?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?std::charisn't specialised for any given locale. Shouldstructoptsupport customised lowercasing based on locale, or should it remain untailored for simplicity of use?Alternatives
nameattribute, rather than thelongattribute. This avoids the problem with unremovable long flag names mentioned above.Anything else?