Skip to content

Commit

Permalink
Merge pull request #3966 from epage/unstable
Browse files Browse the repository at this point in the history
fix!: Remove `unstable-v4` feature gate
  • Loading branch information
epage committed Jul 22, 2022
2 parents 982d4ca + a842bd6 commit 5a4da7e
Show file tree
Hide file tree
Showing 94 changed files with 275 additions and 6,083 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Expand Up @@ -7,8 +7,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## 4.0.0 - Upcoming

_gated behind `unstable-v4`_

### Breaking Changes

- `Error::EmptyValue` replaced with `Error::InvalidValue`
Expand All @@ -25,6 +23,7 @@ _gated behind `unstable-v4`_
- *(assert)* Always enforce that version is specified when the `ArgAction::Version` is used
- *(assert)* Add missing `#[track_caller]`s to make it easier to debug asserts
- *(help)* Use `Command::display_name` in the help title rather than `Command::bin_name`
- *(version)* Use `Command::display_name` rather than `Command::bin_name`
- *(parser)* Assert on unknown args when using external subcommands (#3703)
- *(parser)* Always fill in `""` argument for external subcommands (#3263)
- *(derive)* Detect escaped external subcommands that look like built-in subcommands (#3703)
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -79,8 +79,8 @@ unicode = ["textwrap/unicode-width", "unicase"] # Support for unicode character
# In-work features
unstable-replace = []
unstable-grouped = []
# note: this will always enable clap_derive, change this to `clap_derive?/unstable-v4` when MSRV is bigger than 1.60
unstable-v4 = ["clap_derive/unstable-v4", "deprecated"]
# note: this will always enable clap_derive, change this to `clap_derive?/unstable-v5` when MSRV is bigger than 1.60
unstable-v5 = ["clap_derive/unstable-v5", "deprecated"]

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -17,7 +17,7 @@ _FEATURES_minimal = --no-default-features --features "std"
_FEATURES_default =
_FEATURES_wasm = --features "deprecated derive cargo env unicode unstable-replace unstable-grouped"
_FEATURES_full = --features "deprecated derive cargo env unicode unstable-replace unstable-grouped wrap_help"
_FEATURES_next = ${_FEATURES_full} --features unstable-v4
_FEATURES_next = ${_FEATURES_full} --features unstable-v5
_FEATURES_debug = ${_FEATURES_full} --features debug
_FEATURES_release = ${_FEATURES_full} --release

Expand Down
2 changes: 1 addition & 1 deletion clap_derive/Cargo.toml
Expand Up @@ -49,6 +49,6 @@ proc-macro-error = "1"
[features]
default = []
debug = []
unstable-v4 = ["deprecated"]
unstable-v5 = ["deprecated"]
deprecated = []
raw-deprecated = ["deprecated"]
17 changes: 2 additions & 15 deletions clap_derive/src/attrs.rs
Expand Up @@ -750,16 +750,10 @@ impl Attrs {
quote!( #(#next_help_heading)* #(#help_heading)* )
}

#[cfg(feature = "unstable-v4")]
pub fn id(&self) -> TokenStream {
self.name.clone().raw()
}

#[cfg(not(feature = "unstable-v4"))]
pub fn id(&self) -> TokenStream {
self.cased_name()
}

pub fn cased_name(&self) -> TokenStream {
self.name.clone().translate(*self.casing)
}
Expand All @@ -780,7 +774,7 @@ impl Attrs {
let inner_type = inner_type(field_type);
let span = action.span();
default_value_parser(inner_type, span)
} else if !self.ignore_parser() || cfg!(not(feature = "unstable-v4")) {
} else if !self.ignore_parser() {
self.parser(field_type).value_parser()
} else {
let inner_type = inner_type(field_type);
Expand All @@ -802,7 +796,7 @@ impl Attrs {
if let Some(value_parser) = self.value_parser.as_ref() {
let span = value_parser.span();
default_action(field_type, span)
} else if !self.ignore_parser() || cfg!(not(feature = "unstable-v4")) {
} else if !self.ignore_parser() {
self.parser(field_type).action()
} else {
let span = self
Expand All @@ -815,16 +809,10 @@ impl Attrs {
})
}

#[cfg(feature = "unstable-v4")]
pub fn ignore_parser(&self) -> bool {
self.parser.is_none()
}

#[cfg(not(feature = "unstable-v4"))]
pub fn ignore_parser(&self) -> bool {
self.value_parser.is_some() || self.action.is_some()
}

pub fn explicit_parser(&self) -> bool {
self.parser.is_some()
}
Expand Down Expand Up @@ -1200,7 +1188,6 @@ pub enum Name {
}

impl Name {
#[cfg(feature = "unstable-v4")]
pub fn raw(self) -> TokenStream {
match self {
Name::Assigned(tokens) => tokens,
Expand Down
16 changes: 4 additions & 12 deletions clap_derive/src/derives/subcommand.rs
Expand Up @@ -484,17 +484,9 @@ fn gen_from_arg_matches(
Unnamed(..) => abort_call_site!("{}: tuple enums are not supported", variant.ident),
};

if cfg!(feature = "unstable-v4") {
quote! {
if #sub_name == #subcommand_name_var && !#sub_arg_matches_var.contains_id("") {
return ::std::result::Result::Ok(#name :: #variant_name #constructor_block)
}
}
} else {
quote! {
if #sub_name == #subcommand_name_var {
return ::std::result::Result::Ok(#name :: #variant_name #constructor_block)
}
quote! {
if #sub_name == #subcommand_name_var && !#sub_arg_matches_var.contains_id("") {
return ::std::result::Result::Ok(#name :: #variant_name #constructor_block)
}
}
});
Expand Down Expand Up @@ -528,7 +520,7 @@ fn gen_from_arg_matches(
.chain(
#sub_arg_matches_var
.remove_many::<#str_ty>("")
.into_iter().flatten() // `""` isn't present, bug in `unstable-v4`
.unwrap()
.map(#str_ty::from)
)
.collect::<::std::vec::Vec<_>>()
Expand Down
10 changes: 5 additions & 5 deletions examples/git-derive.md
Expand Up @@ -40,7 +40,7 @@ SUBCOMMANDS:
stash

$ git-derive help add
git-derive[EXE]-add
git-add
adds things

USAGE:
Expand All @@ -58,7 +58,7 @@ A basic argument:
```console
$ git-derive add
? failed
git-derive[EXE]-add
git-add
adds things

USAGE:
Expand All @@ -78,7 +78,7 @@ Adding ["Cargo.toml", "Cargo.lock"]
Default subcommand:
```console
$ git-derive stash -h
git-derive[EXE]-stash
git-stash

USAGE:
git-derive[EXE] stash [OPTIONS]
Expand All @@ -95,7 +95,7 @@ SUBCOMMANDS:
push

$ git-derive stash push -h
git-derive[EXE]-stash-push
git-stash-push

USAGE:
git-derive[EXE] stash push [OPTIONS]
Expand All @@ -105,7 +105,7 @@ OPTIONS:
-m, --message <MESSAGE>

$ git-derive stash pop -h
git-derive[EXE]-stash-pop
git-stash-pop

USAGE:
git-derive[EXE] stash pop [STASH]
Expand Down
10 changes: 5 additions & 5 deletions examples/git.md
Expand Up @@ -38,7 +38,7 @@ SUBCOMMANDS:
stash

$ git help add
git[EXE]-add
git-add
adds things

USAGE:
Expand All @@ -56,7 +56,7 @@ A basic argument:
```console
$ git add
? failed
git[EXE]-add
git-add
adds things

USAGE:
Expand All @@ -76,7 +76,7 @@ Adding ["Cargo.toml", "Cargo.lock"]
Default subcommand:
```console
$ git stash -h
git[EXE]-stash
git-stash

USAGE:
git[EXE] stash [OPTIONS]
Expand All @@ -93,7 +93,7 @@ SUBCOMMANDS:
push

$ git stash push -h
git[EXE]-stash-push
git-stash-push

USAGE:
git[EXE] stash push [OPTIONS]
Expand All @@ -103,7 +103,7 @@ OPTIONS:
-m, --message <MESSAGE>

$ git stash pop -h
git[EXE]-stash-pop
git-stash-pop

USAGE:
git[EXE] stash pop [STASH]
Expand Down
2 changes: 1 addition & 1 deletion examples/pacman.md
Expand Up @@ -52,7 +52,7 @@ SUBCOMMANDS:
sync -S --sync Synchronize packages.

$ pacman -S -h
pacman[EXE]-sync
pacman-sync
Synchronize packages.

USAGE:
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/03_04_subcommands.md
Expand Up @@ -15,7 +15,7 @@ SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)

$ 03_04_subcommands help add
03_04_subcommands[EXE]-add [..]
clap-add 3.2.14
Adds files to myapp

USAGE:
Expand Down Expand Up @@ -59,6 +59,6 @@ $ 03_04_subcommands --version
clap [..]

$ 03_04_subcommands add --version
03_04_subcommands[EXE]-add [..]
clap-add [..]

```
4 changes: 2 additions & 2 deletions examples/tutorial_derive/03_04_subcommands.md
Expand Up @@ -15,7 +15,7 @@ SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)

$ 03_04_subcommands help add
03_04_subcommands[EXE]-add [..]
clap-add 3.2.14
Adds files to myapp

USAGE:
Expand Down Expand Up @@ -59,6 +59,6 @@ $ 03_04_subcommands --version
clap [..]

$ 03_04_subcommands add --version
03_04_subcommands[EXE]-add [..]
clap-add [..]

```
2 changes: 1 addition & 1 deletion src/_features.rs
Expand Up @@ -23,4 +23,4 @@
//!
//! * **unstable-replace**: Enable [`Command::replace`](https://github.com/clap-rs/clap/issues/2836)
//! * **unstable-grouped**: Enable [`ArgMatches::grouped_values_of`](https://github.com/clap-rs/clap/issues/2924)
//! * **unstable-v4**: Preview features which will be stable on the v4.0 release
//! * **unstable-v5**: Preview features which will be stable on the v5.0 release
9 changes: 1 addition & 8 deletions src/builder/arg.rs
Expand Up @@ -186,14 +186,7 @@ impl<'help> Arg<'help> {
#[inline]
#[must_use]
pub fn long(mut self, l: &'help str) -> Self {
#[cfg(feature = "unstable-v4")]
{
self.long = Some(l);
}
#[cfg(not(feature = "unstable-v4"))]
{
self.long = Some(l.trim_start_matches(|c| c == '-'));
}
self.long = Some(l);
self
}

Expand Down
28 changes: 6 additions & 22 deletions src/builder/command.rs
Expand Up @@ -2273,14 +2273,7 @@ impl<'help> Command<'help> {
/// [`Arg::long`]: Arg::long()
#[must_use]
pub fn long_flag(mut self, long: &'help str) -> Self {
#[cfg(feature = "unstable-v4")]
{
self.long_flag = Some(long);
}
#[cfg(not(feature = "unstable-v4"))]
{
self.long_flag = Some(long.trim_start_matches(|c| c == '-'));
}
self.long_flag = Some(long);
self
}

Expand Down Expand Up @@ -4398,16 +4391,8 @@ To change `help`s short, call `cmd.arg(Arg::new(\"help\")...)`.",
} else {
self.version.or(self.long_version).unwrap_or("")
};
if let Some(bn) = self.bin_name.as_ref() {
if bn.contains(' ') {
// In case we're dealing with subcommands i.e. git mv is translated to git-mv
format!("{} {}\n", bn.replace(' ', "-"), ver)
} else {
format!("{} {}\n", &self.name[..], ver)
}
} else {
format!("{} {}\n", &self.name[..], ver)
}
let display_name = self.get_display_name().unwrap_or_else(|| self.get_name());
format!("{} {}\n", display_name, ver)
}

pub(crate) fn format_group(&self, g: &Id) -> String {
Expand Down Expand Up @@ -4674,10 +4659,9 @@ impl<'help> Command<'help> {
v.long_help.is_some()
|| v.is_hide_long_help_set()
|| v.is_hide_short_help_set()
|| cfg!(feature = "unstable-v4")
&& v.get_possible_values()
.iter()
.any(PossibleValue::should_show_help)
|| v.get_possible_values()
.iter()
.any(PossibleValue::should_show_help)
};

// Subcommands aren't checked because we prefer short help for them, deferring to
Expand Down

0 comments on commit 5a4da7e

Please sign in to comment.