1 //! Example on how the `rename_all` parameter works.
2 //!
3 //! `rename_all` can be used to override the casing style used during argument
4 //! generation. By default the `kebab-case` style will be used but there are a wide
5 //! variety of other styles available.
6 //!
7 //! ## Supported styles overview:
8 //!
9 //! - **Camel Case**: Indicate word boundaries with uppercase letter, excluding
10 //! the first word.
11 //! - **Kebab Case**: Keep all letters lowercase and indicate word boundaries
12 //! with hyphens.
13 //! - **Pascal Case**: Indicate word boundaries with uppercase letter,
14 //! including the first word.
15 //! - **Screaming Snake Case**: Keep all letters uppercase and indicate word
16 //! boundaries with underscores.
17 //! - **Snake Case**: Keep all letters lowercase and indicate word boundaries
18 //! with underscores.
19 //! - **Verbatim**: Use the original attribute name defined in the code.
20 //!
21 //! - **Lower Case**: Keep all letters lowercase and remove word boundaries.
22 //!
23 //! - **Upper Case**: Keep all letters uppercase and remove word boundaries.
24 //!
25 //! Running this example with --help prints this message:
26 //! -----------------------------------------------------
27 //! rename_all 0.3.25
28 //!
29 //! USAGE:
30 //! rename_all <SUBCOMMAND>
31 //!
32 //! FLAGS:
33 //! -h, --help Prints help information
34 //! -V, --version Prints version information
35 //!
36 //! SUBCOMMANDS:
37 //! FIRST_COMMAND A screaming loud first command. Only use if necessary
38 //! SecondCommand Not nearly as loud as the first command
39 //! help Prints this message or the help of the given subcommand(s)
40 //! -----------------------------------------------------
41
42 use structopt::StructOpt;
43
44 #[derive(StructOpt, Debug)]
45 #[structopt(name = "rename_all", rename_all = "screaming_snake_case")]
46 enum Opt {
47 // This subcommand will be named `FIRST_COMMAND`. As the command doesn't
48 // override the initial casing style, ...
49 /// A screaming loud first command. Only use if necessary.
50 FirstCommand {
51 // this flag will be available as `--FOO` and `-F`.
52 /// This flag will even scream louder.
53 #[structopt(long, short)]
54 foo: bool,
55 },
56
57 // As we override the casing style for this variant the related subcommand
58 // will be named `SecondCommand`.
59 /// Not nearly as loud as the first command.
60 #[structopt(rename_all = "pascal_case")]
61 SecondCommand {
62 // We can also override it again on a single field.
63 /// Nice quiet flag. No one is annoyed.
64 #[structopt(rename_all = "snake_case", long)]
65 bar_option: bool,
66
67 // Renaming will not be propagated into subcommand flagged enums. If
68 // a non default casing style is required it must be defined on the
69 // enum itself.
70 #[structopt(subcommand)]
71 cmds: Subcommands,
72
73 // or flattened structs.
74 #[structopt(flatten)]
75 options: BonusOptions,
76 },
77 }
78
79 #[derive(StructOpt, Debug)]
80 enum Subcommands {
81 // This one will be available as `first-subcommand`.
82 FirstSubcommand,
83 }
84
85 #[derive(StructOpt, Debug)]
86 struct BonusOptions {
87 // And this one will be available as `baz-option`.
88 #[structopt(long)]
89 baz_option: bool,
90 }
91
main()92 fn main() {
93 let opt = Opt::from_args();
94 println!("{:?}", opt);
95 }
96