Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Casing] Change default from verbatim to kebab. #204

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
as `Option<Vec<T>>` is handled differently. If you need to have a `Option<Vec<T>>`
handled the old was, you can `type Something = Vec<T>;` and then use `Option<Something>`
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

Expand Down
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
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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