Skip to content

Commit 7515bfe

Browse files
committed
fix: Allow people to opt-in to deprecations
This adds a new `Cargo.toml` feature named `deprecated` that opts controls whether deprecation warnings show up. This is starting off as non-default though that may change (see below). Benefits - Allows a staged rollout so a smaller subset of users see new deprecations and can report their experience with them before everyone sees them. For example, this reduces the number of people who have to deal with #3822. - This allows people to defer responding to each new batch of deprecations and instead do it at once. This means we should reconsider #3616. The one risk is people who don't follow blog posts and guides having a harder time upgrading to the next breaking release without the warnings on by default. For these users, we reserve the right to make the `deprecated` feature `default`. This is most likely to happen in a minor release that is released in conjunction with the next major release (e.g. when releasing 4.0.0, we release a 3.3.0 that enables deprecations by default). By using a feature, users can still disable this if they want. Thanks @joshtriplett for the idea
1 parent d71e38e commit 7515bfe

19 files changed

+906
-402
lines changed

CONTRIBUTING.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ Our releases fall into one of:
3838
- Aspire to at least 6-9 months between releases
3939
- Remove all deprecated functionality
4040
- Try to minimize new breaking changes to ease user transition and reduce time "we go dark" (unreleased feature-branch)
41+
- Upon release, a minor release will be made for the previous major that enables `deprecated` feature by default
4142
- Minor releases which are for minor compatibility changes
4243
- Aspire to at least 2 months between releases
4344
- Changes to MSRV
44-
- Deprecating existing functionality
45+
- Deprecating existing functionality (behind the `deprecated` feature flag)
46+
- Making the `deprecated` feature flag enabled-by-default (only on last planned minor release)
4547
- `#[doc(hidden)]` all deprecated items in the prior minor release
4648
- Patch releases
4749
- One for every user-facing, user-contributed PR (i.e. release early, release often)
@@ -51,7 +53,7 @@ If your change does not fit within a "patch" release, please coordinate with the
5153
Some practices to avoid breaking changes
5254
- Duplicate functionality, with old functionality marked as "deprecated"
5355
- Common documentation pattern: `/// Deprecated in [Issue #XXX](https://github.com/clap-rs/clap/issues/XXX), replaced with [intra-doc-link]`
54-
- Common deprecation pattern: `#[deprecated(since = "X.Y.Z", note = "Replaced with `ITEM` in Issue #XXX")]`
56+
- Common deprecation pattern: `#[cfg_attr(feature = "deprecated", deprecated(since = "X.Y.Z", note = "Replaced with `ITEM` in Issue #XXX"))]`
5557
- Please keep API addition and deprecation in separate commits in a PR to make it easier to review
5658
- Develop the feature behind an `unstable-<name>` feature flag with a stablization tracking issue (e.g. [Multicall Tracking issue](https://github.com/clap-rs/clap/issues/2861))
5759

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ color = ["atty", "termcolor"]
7373
suggestions = ["strsim"]
7474

7575
# Optional
76+
deprecated = [] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
7677
derive = ["clap_derive", "once_cell"]
7778
cargo = ["once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
7879
wrap_help = ["terminal_size", "textwrap/terminal_size"]
@@ -84,7 +85,7 @@ unicode = ["textwrap/unicode-width", "unicase"] # Support for unicode character
8485
unstable-replace = []
8586
unstable-grouped = []
8687
# note: this will always enable clap_derive, change this to `clap_derive?/unstable-v4` when MSRV is bigger than 1.60
87-
unstable-v4 = ["clap_derive/unstable-v4"]
88+
unstable-v4 = ["clap_derive/unstable-v4", "deprecated"]
8889

8990
[lib]
9091
bench = false

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ MSRV?=1.56.0
1515
_FEATURES = minimal default wasm full debug release
1616
_FEATURES_minimal = --no-default-features --features "std"
1717
_FEATURES_default =
18-
_FEATURES_wasm = --features "derive cargo env unicode yaml regex unstable-replace unstable-grouped"
19-
_FEATURES_full = --features "derive cargo env unicode yaml regex unstable-replace unstable-grouped wrap_help"
18+
_FEATURES_wasm = --features "deprecated derive cargo env unicode yaml regex unstable-replace unstable-grouped"
19+
_FEATURES_full = --features "deprecated derive cargo env unicode yaml regex unstable-replace unstable-grouped wrap_help"
2020
_FEATURES_next = ${_FEATURES_full} --features unstable-v4
2121
_FEATURES_debug = ${_FEATURES_full} --features debug
2222
_FEATURES_release = ${_FEATURES_full} --release

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.2.2
140140

141141
#### Optional features
142142

143+
* **deprecated**: Guided experience to prepare for next breaking release (at different stages of development, this may become default)
143144
* **derive**: Enables the custom derive (i.e. `#[derive(Parser)]`). Without this you must use one of the other methods of creating a `clap` CLI listed above.
144145
* **cargo**: Turns on macros that read values from `CARGO_*` environment variables.
145146
* **env**: Turns on the usage of environment variables during parsing.

src/builder/action.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,21 @@ pub enum ArgAction {
7171
/// ```
7272
Append,
7373
/// Deprecated, replaced with [`ArgAction::Set`] or [`ArgAction::Append`]
74-
#[deprecated(
75-
since = "3.2.0",
76-
note = "Replaced with `ArgAction::Set` or `ArgAction::Append`"
74+
#[cfg_attr(
75+
feature = "deprecated",
76+
deprecated(
77+
since = "3.2.0",
78+
note = "Replaced with `ArgAction::Set` or `ArgAction::Append`"
79+
)
7780
)]
7881
StoreValue,
7982
/// Deprecated, replaced with [`ArgAction::SetTrue`] or [`ArgAction::Count`]
80-
#[deprecated(
81-
since = "3.2.0",
82-
note = "Replaced with `ArgAction::SetTrue` or `ArgAction::Count`"
83+
#[cfg_attr(
84+
feature = "deprecated",
85+
deprecated(
86+
since = "3.2.0",
87+
note = "Replaced with `ArgAction::SetTrue` or `ArgAction::Count`"
88+
)
8389
)]
8490
IncOccurrence,
8591
/// When encountered, act as if `"true"` was encountered on the command-line

0 commit comments

Comments
 (0)