Skip to content

Commit 4ed6ddb

Browse files
authored
Merge pull request #4805 from epage/replace
fix!: Remove `unstable-replace` feature flag
2 parents 79be4bd + 56fe5e0 commit 4ed6ddb

File tree

8 files changed

+3
-170
lines changed

8 files changed

+3
-170
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ unicode = ["clap_builder/unicode"] # Support for unicode characters in argument
9292
string = ["clap_builder/string"] # Allow runtime generated strings
9393

9494
# In-work features
95-
unstable-replace = ["clap_builder/unstable-replace"]
9695
unstable-v5 = ["clap_builder/unstable-v5", "clap_derive?/unstable-v5", "deprecated"]
9796

9897
[lib]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ MSRV?=1.64.0
1515
_FEATURES = minimal default wasm full debug release
1616
_FEATURES_minimal = --no-default-features --features "std"
1717
_FEATURES_default =
18-
_FEATURES_wasm = --no-default-features --features "std help usage error-context suggestions" --features "deprecated derive cargo env unicode string unstable-replace"
19-
_FEATURES_full = --features "deprecated derive cargo env unicode string unstable-replace wrap_help"
18+
_FEATURES_wasm = --no-default-features --features "std help usage error-context suggestions" --features "deprecated derive cargo env unicode string"
19+
_FEATURES_full = --features "deprecated derive cargo env unicode string wrap_help"
2020
_FEATURES_next = ${_FEATURES_full} --features unstable-v5
2121
_FEATURES_debug = ${_FEATURES_full} --features debug --features clap_complete/debug
2222
_FEATURES_release = ${_FEATURES_full} --release

clap_builder/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tag-name = "v{{version}}"
3232
[features]
3333
default = ["std", "color", "help", "usage", "error-context", "suggestions"]
3434
debug = ["dep:backtrace"] # Enables debug messages
35-
unstable-doc = ["cargo", "wrap_help", "env", "unicode", "string", "unstable-replace"] # for docs.rs
35+
unstable-doc = ["cargo", "wrap_help", "env", "unicode", "string"] # for docs.rs
3636

3737
# Used in default
3838
std = [] # support for no_std in a backwards-compatible way
@@ -51,7 +51,6 @@ unicode = ["dep:unicode-width", "dep:unicase"] # Support for unicode characters
5151
string = [] # Allow runtime generated strings
5252

5353
# In-work features
54-
unstable-replace = []
5554
unstable-v5 = ["deprecated"]
5655

5756
[lib]

clap_builder/src/builder/command.rs

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::output::fmt::Stream;
2424
use crate::output::{fmt::Colorizer, write_help, Usage};
2525
use crate::parser::{ArgMatcher, ArgMatches, Parser};
2626
use crate::util::ChildGraph;
27-
use crate::util::FlatMap;
2827
use crate::util::{color::ColorChoice, Id};
2928
use crate::{Error, INTERNAL_ERROR_MSG};
3029

@@ -99,7 +98,6 @@ pub struct Command {
9998
g_settings: AppFlags,
10099
args: MKeyMap,
101100
subcommands: Vec<Command>,
102-
replacers: FlatMap<Str, Vec<Str>>,
103101
groups: Vec<ArgGroup>,
104102
current_help_heading: Option<Str>,
105103
current_disp_ord: Option<usize>,
@@ -1924,129 +1922,6 @@ impl Command {
19241922
self
19251923
}
19261924

1927-
/// Replaces an argument or subcommand used on the CLI at runtime with other arguments or subcommands.
1928-
///
1929-
/// **Note:** This is gated behind [`unstable-replace`](https://github.com/clap-rs/clap/issues/2836)
1930-
///
1931-
/// When this method is used, `name` is removed from the CLI, and `target`
1932-
/// is inserted in its place. Parsing continues as if the user typed
1933-
/// `target` instead of `name`.
1934-
///
1935-
/// This can be used to create "shortcuts" for subcommands, or if a
1936-
/// particular argument has the semantic meaning of several other specific
1937-
/// arguments and values.
1938-
///
1939-
/// # Examples
1940-
///
1941-
/// We'll start with the "subcommand short" example. In this example, let's
1942-
/// assume we have a program with a subcommand `module` which can be invoked
1943-
/// via `cmd module`. Now let's also assume `module` also has a subcommand
1944-
/// called `install` which can be invoked `cmd module install`. If for some
1945-
/// reason users needed to be able to reach `cmd module install` via the
1946-
/// short-hand `cmd install`, we'd have several options.
1947-
///
1948-
/// We *could* create another sibling subcommand to `module` called
1949-
/// `install`, but then we would need to manage another subcommand and manually
1950-
/// dispatch to `cmd module install` handling code. This is error prone and
1951-
/// tedious.
1952-
///
1953-
/// We could instead use [`Command::replace`] so that, when the user types `cmd
1954-
/// install`, `clap` will replace `install` with `module install` which will
1955-
/// end up getting parsed as if the user typed the entire incantation.
1956-
///
1957-
/// ```rust
1958-
/// # use clap_builder as clap;
1959-
/// # use clap::Command;
1960-
/// let m = Command::new("cmd")
1961-
/// .subcommand(Command::new("module")
1962-
/// .subcommand(Command::new("install")))
1963-
/// .replace("install", &["module", "install"])
1964-
/// .get_matches_from(vec!["cmd", "install"]);
1965-
///
1966-
/// assert!(m.subcommand_matches("module").is_some());
1967-
/// assert!(m.subcommand_matches("module").unwrap().subcommand_matches("install").is_some());
1968-
/// ```
1969-
///
1970-
/// Now let's show an argument example!
1971-
///
1972-
/// Let's assume we have an application with two flags `--save-context` and
1973-
/// `--save-runtime`. But often users end up needing to do *both* at the
1974-
/// same time. We can add a third flag `--save-all` which semantically means
1975-
/// the same thing as `cmd --save-context --save-runtime`. To implement that,
1976-
/// we have several options.
1977-
///
1978-
/// We could create this third argument and manually check if that argument
1979-
/// and in our own consumer code handle the fact that both `--save-context`
1980-
/// and `--save-runtime` *should* have been used. But again this is error
1981-
/// prone and tedious. If we had code relying on checking `--save-context`
1982-
/// and we forgot to update that code to *also* check `--save-all` it'd mean
1983-
/// an error!
1984-
///
1985-
/// Luckily we can use [`Command::replace`] so that when the user types
1986-
/// `--save-all`, `clap` will replace that argument with `--save-context
1987-
/// --save-runtime`, and parsing will continue like normal. Now all our code
1988-
/// that was originally checking for things like `--save-context` doesn't
1989-
/// need to change!
1990-
///
1991-
/// ```rust
1992-
/// # use clap_builder as clap;
1993-
/// # use clap::{Command, Arg, ArgAction};
1994-
/// let m = Command::new("cmd")
1995-
/// .arg(Arg::new("save-context")
1996-
/// .long("save-context")
1997-
/// .action(ArgAction::SetTrue))
1998-
/// .arg(Arg::new("save-runtime")
1999-
/// .long("save-runtime")
2000-
/// .action(ArgAction::SetTrue))
2001-
/// .replace("--save-all", &["--save-context", "--save-runtime"])
2002-
/// .get_matches_from(vec!["cmd", "--save-all"]);
2003-
///
2004-
/// assert!(m.get_flag("save-context"));
2005-
/// assert!(m.get_flag("save-runtime"));
2006-
/// ```
2007-
///
2008-
/// This can also be used with options, for example if our application with
2009-
/// `--save-*` above also had a `--format=TYPE` option. Let's say it
2010-
/// accepted `txt` or `json` values. However, when `--save-all` is used,
2011-
/// only `--format=json` is allowed, or valid. We could change the example
2012-
/// above to enforce this:
2013-
///
2014-
/// ```rust
2015-
/// # use clap_builder as clap;
2016-
/// # use clap::{Command, Arg, ArgAction};
2017-
/// let m = Command::new("cmd")
2018-
/// .arg(Arg::new("save-context")
2019-
/// .long("save-context")
2020-
/// .action(ArgAction::SetTrue))
2021-
/// .arg(Arg::new("save-runtime")
2022-
/// .long("save-runtime")
2023-
/// .action(ArgAction::SetTrue))
2024-
/// .arg(Arg::new("format")
2025-
/// .long("format")
2026-
/// .action(ArgAction::Set)
2027-
/// .value_parser(["txt", "json"]))
2028-
/// .replace("--save-all", &["--save-context", "--save-runtime", "--format=json"])
2029-
/// .get_matches_from(vec!["cmd", "--save-all"]);
2030-
///
2031-
/// assert!(m.get_flag("save-context"));
2032-
/// assert!(m.get_flag("save-runtime"));
2033-
/// assert_eq!(m.get_one::<String>("format").unwrap(), "json");
2034-
/// ```
2035-
///
2036-
/// [`Command::replace`]: Command::replace()
2037-
#[inline]
2038-
#[cfg(feature = "unstable-replace")]
2039-
#[must_use]
2040-
pub fn replace(
2041-
mut self,
2042-
name: impl Into<Str>,
2043-
target: impl IntoIterator<Item = impl Into<Str>>,
2044-
) -> Self {
2045-
self.replacers
2046-
.insert(name.into(), target.into_iter().map(Into::into).collect());
2047-
self
2048-
}
2049-
20501925
/// Exit gracefully if no arguments are present (e.g. `$ myprog`).
20511926
///
20521927
/// **NOTE:** [`subcommands`] count as arguments
@@ -3853,10 +3728,6 @@ impl Command {
38533728
self.max_w
38543729
}
38553730

3856-
pub(crate) fn get_replacement(&self, key: &str) -> Option<&[Str]> {
3857-
self.replacers.get(key).map(|v| v.as_slice())
3858-
}
3859-
38603731
pub(crate) fn get_keymap(&self) -> &MKeyMap {
38613732
&self.args
38623733
}
@@ -4749,7 +4620,6 @@ impl Default for Command {
47494620
g_settings: Default::default(),
47504621
args: Default::default(),
47514622
subcommands: Default::default(),
4752-
replacers: Default::default(),
47534623
groups: Default::default(),
47544624
current_help_heading: Default::default(),
47554625
current_disp_ord: Some(0),

clap_builder/src/parser/parser.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,6 @@ impl<'cmd> Parser<'cmd> {
7676
let contains_last = self.cmd.get_arguments().any(|x| x.is_last_set());
7777

7878
while let Some(arg_os) = raw_args.next(&mut args_cursor) {
79-
// Recover the replaced items if any.
80-
if let Some(replaced_items) = arg_os
81-
.to_value()
82-
.ok()
83-
.and_then(|a| self.cmd.get_replacement(a))
84-
{
85-
debug!(
86-
"Parser::get_matches_with: found replacer: {:?}, target: {:?}",
87-
arg_os, replaced_items
88-
);
89-
raw_args.insert(&args_cursor, replaced_items);
90-
continue;
91-
}
92-
9379
debug!(
9480
"Parser::get_matches_with: Begin parsing '{:?}'",
9581
arg_os.to_value_os(),

src/_features.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@
2525
//!
2626
//! **Warning:** These may contain breaking changes between minor releases.
2727
//!
28-
//! * **unstable-replace**: Enable [`Command::replace`](https://github.com/clap-rs/clap/issues/2836)
2928
//! * **unstable-v5**: Preview features which will be stable on the v5.0 release

tests/builder/subcommands.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,6 @@ Options:
225225
utils::assert_output(cmd, "clap-test --help", INVISIBLE_ALIAS_HELP, false);
226226
}
227227

228-
#[test]
229-
#[cfg(feature = "unstable-replace")]
230-
fn replace() {
231-
let m = Command::new("prog")
232-
.subcommand(
233-
Command::new("module").subcommand(Command::new("install").about("Install module")),
234-
)
235-
.replace("install", ["module", "install"])
236-
.try_get_matches_from(vec!["prog", "install"])
237-
.unwrap();
238-
239-
assert_eq!(m.subcommand_name(), Some("module"));
240-
assert_eq!(
241-
m.subcommand_matches("module").unwrap().subcommand_name(),
242-
Some("install")
243-
);
244-
}
245-
246228
#[test]
247229
fn issue_1031_args_with_same_name() {
248230
let res = Command::new("prog")

tests/ui.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ fn ui_tests() {
2525
"string",
2626
#[cfg(feature = "wrap_help")]
2727
"wrap_help",
28-
#[cfg(feature = "unstable-replace")]
29-
"unstable-replace",
3028
]
3129
.join(" ");
3230
t.register_bins(trycmd::cargo::compile_examples(["--features", &features]).unwrap());

0 commit comments

Comments
 (0)