Skip to content

Commit

Permalink
[Casing] Change default from verbatim to kebab.
Browse files Browse the repository at this point in the history
.. fixes #202
  • Loading branch information
0ndorio committed Jun 17, 2019
1 parent 50e7edd commit 8545506
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/rename_all.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
18 changes: 9 additions & 9 deletions tests/argument_naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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 },
}

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"]))
);
}

Expand All @@ -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 {
Expand All @@ -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"]))
);
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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"]))
);
}

Expand Down Expand Up @@ -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"]))
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/deny-warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
);
}
2 changes: 1 addition & 1 deletion tests/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8545506

Please sign in to comment.