diff --git a/CHANGELOG.md b/CHANGELOG.md index 0533c634..1e92dc64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ as `Option>` is handled differently. If you need to have a `Option>` handled the old was, you can `type Something = Vec;` and then use `Option` as your structopt field. +* Change default case from 'Verbatim' into 'Kebab' by [@0ndorio](https://github.com/0ndorio) + ([#202](https://github.com/TeXitoi/structopt/issues/202)). This is a breaking change. + If you rely on the old behavior you need to add `#[structopt(rename_all = "verbatim")]` + as an attribute to each data structure deriving the `StructOpt` trait. ## improvements diff --git a/examples/rename_all.rs b/examples/rename_all.rs index 36ac12e7..9938c67c 100644 --- a/examples/rename_all.rs +++ b/examples/rename_all.rs @@ -1,7 +1,7 @@ //! Example on how the `rename_all` parameter works. //! //! `rename_all` can be used to override the casing style used during argument -//! generation. By default the `verbatim-case` style will be used but there are a wide +//! generation. By default the `kebab-case` style will be used but there are a wide //! variety of other styles available. //! //! ## Supported styles overview: @@ -59,13 +59,13 @@ enum Opt { #[derive(StructOpt, Debug)] enum Subcommands { - // This one will be available as `FirstSubcommand`. + // This one will be available as `first-subcommand`. FirstSubcommand, } #[derive(StructOpt, Debug)] struct BonusOptions { - // And this one will be available as `baz_option`. + // And this one will be available as `baz-option`. #[structopt(long)] baz_option: bool, } diff --git a/src/lib.rs b/src/lib.rs index 492355c1..f04320b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -186,6 +186,11 @@ //! If an argument is renamed using `name = $NAME` any following call to //! `short` or `long` will use the new name. //! +//! **Attention**: If these arguments are used without an explicit name +//! the resulting flag is going to be renamed using `kebab-case` if the +//! `rename_all` attribute was not specified previously. The same is true +//! for subcommands with implicit naming through the related data structure. +//! //! ``` //! #[macro_use] //! extern crate structopt; diff --git a/structopt-derive/src/lib.rs b/structopt-derive/src/lib.rs index 276fa7ed..017aa169 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -26,7 +26,7 @@ use syn::token::Comma; use syn::*; /// Default casing style for generated arguments. -const DEFAULT_CASING: CasingStyle = CasingStyle::Verbatim; +const DEFAULT_CASING: CasingStyle = CasingStyle::Kebab; /// Output for the `gen_xxx()` methods were we need more than a simple stream of tokens. /// diff --git a/tests/argument_naming.rs b/tests/argument_naming.rs index d37a9e3b..ca68d729 100644 --- a/tests/argument_naming.rs +++ b/tests/argument_naming.rs @@ -4,7 +4,7 @@ extern crate structopt; use structopt::StructOpt; #[test] -fn test_single_word_enum_variant_is_default_renamed_into_verbatim_case() { +fn test_single_word_enum_variant_is_default_renamed_into_kebab_case() { #[derive(StructOpt, Debug, PartialEq)] enum Opt { Command { foo: u32 }, @@ -12,7 +12,7 @@ fn test_single_word_enum_variant_is_default_renamed_into_verbatim_case() { assert_eq!( Opt::Command { foo: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "Command", "0"])) + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "command", "0"])) ); } @@ -25,12 +25,12 @@ fn test_multi_word_enum_variant_is_renamed() { assert_eq!( Opt::FirstCommand { foo: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "FirstCommand", "0"])) + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "first-command", "0"])) ); } #[test] -fn test_standalone_long_generates_verbatim_case() { +fn test_standalone_long_generates_kebab_case() { #[derive(StructOpt, Debug, PartialEq)] #[allow(non_snake_case)] struct Opt { @@ -40,7 +40,7 @@ fn test_standalone_long_generates_verbatim_case() { assert_eq!( Opt { FOO_OPTION: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--FOO_OPTION"])) + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo-option"])) ); } @@ -82,12 +82,12 @@ fn test_standalone_long_ignores_afterwards_defined_custom_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo_option"])) + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo-option"])) ); } #[test] -fn test_standalone_short_generates_verbatim_case() { +fn test_standalone_short_generates_kebab_case() { #[derive(StructOpt, Debug, PartialEq)] #[allow(non_snake_case)] struct Opt { @@ -97,7 +97,7 @@ fn test_standalone_short_generates_verbatim_case() { assert_eq!( Opt { FOO_OPTION: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-F"])) + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-f"])) ); } @@ -259,7 +259,7 @@ fn test_rename_all_is_not_propagated_from_struct_into_subcommand() { Opt { foo: Foo::Command { foo: true } }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "Command", "--foo"])) + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "command", "--foo"])) ); } diff --git a/tests/deny-warnings.rs b/tests/deny-warnings.rs index dbc15358..9f203fcb 100644 --- a/tests/deny-warnings.rs +++ b/tests/deny-warnings.rs @@ -46,6 +46,6 @@ fn warning_never_enum() { Opt::Foo { s: "foo".to_string() }, - Opt::from_iter(&["test", "Foo", "foo"]) + Opt::from_iter(&["test", "foo", "foo"]) ); } diff --git a/tests/subcommands.rs b/tests/subcommands.rs index 6ae9b3b2..8f4f6ebe 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -217,7 +217,7 @@ fn flatten_enum() { assert!(Opt::from_iter_safe(&["test"]).is_err()); assert_eq!( - Opt::from_iter(&["test", "Foo"]), + Opt::from_iter(&["test", "foo"]), Opt { sub_cmd: SubCmd::Foo }