Skip to content

Commit

Permalink
Merge clap-rs#2837
Browse files Browse the repository at this point in the history
2837: fix: Gate App::replace r=pksunkara a=epage



Co-authored-by: Ed Page <[email protected]>
  • Loading branch information
bors[bot] and epage authored Oct 9, 2021
2 parents 6919ee5 + dfbeb71 commit e8ec11e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
test-full:
name: Tests (Full)
env:
FLAGS: --features 'wrap_help yaml regex'
FLAGS: --features 'wrap_help yaml regex unstable-replace'
strategy:
fail-fast: false
matrix:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ jobs:
if: matrix.features == 'all'
with:
command: test
args: --target ${{ matrix.target }} --features "wrap_help yaml regex"
args: --target ${{ matrix.target }} --features "wrap_help yaml regex unstable-replace"
- name: Check debug
uses: actions-rs/cargo@v1
if: matrix.features == 'all'
with:
command: check
args: --target ${{ matrix.target }} --features "wrap_help yaml regex debug"
args: --target ${{ matrix.target }} --features "wrap_help yaml regex unstable-replace debug"
- name: Test release
uses: actions-rs/cargo@v1
if: matrix.features == 'release'
Expand Down Expand Up @@ -139,13 +139,13 @@ jobs:
if: matrix.features == 'all'
with:
command: test
args: --features "wrap_help yaml regex"
args: --features "wrap_help yaml regex unstable-replace"
- name: Check debug
uses: actions-rs/cargo@v1
if: matrix.features == 'all'
with:
command: check
args: --features "wrap_help yaml regex debug"
args: --features "wrap_help yaml regex unstable-replace debug"
- name: Test release
uses: actions-rs/cargo@v1
if: matrix.features == 'release'
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ TODO: `YamlLoader`

* **Renamed Features**
* `unicode_help` to `unicode` to encompass more functionality
* **Gated Features**
* `App::replace` is now gated behind `unstable-replace`

* **Removed Settings**
* `AppSettings::DisableVersionForSubcommands`
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ unicode = ["textwrap/unicode-width", "unicase"] # Support for unicode character
wrap_help = ["terminal_size", "textwrap/terminal_size"]
yaml = ["yaml-rust"]

# In-work features
unstable-replace = []

[profile.test]
opt-level = 1

Expand All @@ -114,7 +117,7 @@ lto = true
codegen-units = 1

[package.metadata.docs.rs]
features = ["yaml", "regex"]
features = ["yaml", "regex", "unstable-replace"]
targets = ["x86_64-unknown-linux-gnu"]

[workspace]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ features = ["std", "suggestions", "color"]
* **wrap_help**: Turns on the help text wrapping feature, based on the terminal size. (builds dependency `term-size`)
* **yaml**: Enables building CLIs from YAML documents. (builds dependency `yaml-rust`)

#### Experimental features

* **unstable-replace**: Enable [`App::replace`](https://github.com/clap-rs/clap/issues/2836)

### More Information

You can find complete documentation on the [docs.rs][docs] for this project.
Expand Down
3 changes: 3 additions & 0 deletions src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,8 @@ impl<'help> App<'help> {

/// Replaces an argument or subcommand used on the CLI at runtime with other arguments or subcommands.
///
/// **Note:** This is gated behind [`unstable-replace`](https://github.com/clap-rs/clap/issues/2836)
///
/// When this method is used, `name` is removed from the CLI, and `target`
/// is inserted in its place. Parsing continues as if the user typed
/// `target` instead of `name`.
Expand Down Expand Up @@ -1539,6 +1541,7 @@ impl<'help> App<'help> {
///
/// [`App::replace`]: App::replace()
#[inline]
#[cfg(feature = "unstable-replace")]
pub fn replace(mut self, name: &'help str, target: &'help [&'help str]) -> Self {
self.replacers.insert(name, target);
self
Expand Down
1 change: 1 addition & 0 deletions tests/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ fn invisible_aliases_help_output() {
}

#[test]
#[cfg(feature = "unstable-replace")]
fn replace() {
let m = App::new("prog")
.subcommand(App::new("module").subcommand(App::new("install").about("Install module")))
Expand Down

0 comments on commit e8ec11e

Please sign in to comment.