From 85455061f3e8106eb0a39a5f5563277f905c2848 Mon Sep 17 00:00:00 2001 From: Bruno Kirschner Date: Mon, 17 Jun 2019 23:48:43 +0200 Subject: [PATCH] [Casing] Change default from verbatim to kebab. .. fixes TeXitoi/structopt#202 --- examples/rename_all.rs | 6 +++--- structopt-derive/src/lib.rs | 2 +- tests/argument_naming.rs | 18 +++++++++--------- tests/deny-warnings.rs | 2 +- tests/subcommands.rs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) 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/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 }