mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 06:12:40 +00:00
fix(derive): Allow opting in to the original deprecations
This commit is contained in:
parent
ae81b09359
commit
11fe3ce404
4 changed files with 25 additions and 6 deletions
|
@ -73,7 +73,8 @@ color = ["atty", "termcolor"]
|
|||
suggestions = ["strsim"]
|
||||
|
||||
# Optional
|
||||
deprecated = [] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
|
||||
# note: this will always enable clap_derive, change this to `clap_derive?/unstable-v4` when MSRV is bigger than 1.60
|
||||
deprecated = ["clap_derive/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
|
||||
derive = ["clap_derive", "once_cell"]
|
||||
cargo = ["once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
|
||||
wrap_help = ["terminal_size", "textwrap/terminal_size"]
|
||||
|
|
|
@ -51,4 +51,6 @@ proc-macro-error = "1"
|
|||
[features]
|
||||
default = []
|
||||
debug = []
|
||||
unstable-v4 = []
|
||||
unstable-v4 = ["deprecated"]
|
||||
deprecated = []
|
||||
raw-deprecated = ["deprecated"]
|
||||
|
|
|
@ -113,6 +113,7 @@ pub fn gen_from_arg_matches_for_struct(
|
|||
|
||||
let constructor = gen_constructor(fields, &attrs);
|
||||
let updater = gen_updater(fields, &attrs, true);
|
||||
let raw_deprecated = raw_deprecated();
|
||||
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
|
||||
|
@ -136,7 +137,7 @@ pub fn gen_from_arg_matches_for_struct(
|
|||
}
|
||||
|
||||
fn from_arg_matches_mut(__clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
||||
#[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Args`
|
||||
#raw_deprecated
|
||||
let v = #struct_name #constructor;
|
||||
::std::result::Result::Ok(v)
|
||||
}
|
||||
|
@ -146,7 +147,7 @@ pub fn gen_from_arg_matches_for_struct(
|
|||
}
|
||||
|
||||
fn update_from_arg_matches_mut(&mut self, __clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result<(), clap::Error> {
|
||||
#[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Args`
|
||||
#raw_deprecated
|
||||
#updater
|
||||
::std::result::Result::Ok(())
|
||||
}
|
||||
|
@ -737,3 +738,16 @@ fn gen_parsers(
|
|||
quote_spanned!(field.span()=> #field_name: #field_value )
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "raw-deprecated")]
|
||||
pub fn raw_deprecated() -> TokenStream {
|
||||
quote! {}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "raw-deprecated"))]
|
||||
pub fn raw_deprecated() -> TokenStream {
|
||||
quote! {
|
||||
#![allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Args`
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -540,9 +540,10 @@ fn gen_from_arg_matches(
|
|||
},
|
||||
};
|
||||
|
||||
let raw_deprecated = args::raw_deprecated();
|
||||
quote! {
|
||||
fn from_arg_matches_mut(__clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
|
||||
#[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Subcommand`
|
||||
#raw_deprecated
|
||||
|
||||
#( #child_subcommands )else*
|
||||
|
||||
|
@ -654,12 +655,13 @@ fn gen_update_from_arg_matches(
|
|||
}
|
||||
});
|
||||
|
||||
let raw_deprecated = args::raw_deprecated();
|
||||
quote! {
|
||||
fn update_from_arg_matches_mut<'b>(
|
||||
&mut self,
|
||||
__clap_arg_matches: &mut clap::ArgMatches,
|
||||
) -> ::std::result::Result<(), clap::Error> {
|
||||
#[allow(deprecated)] // Assuming any deprecation in here will be related to a deprecation in `Subcommand`
|
||||
#raw_deprecated
|
||||
|
||||
if let Some(__clap_name) = __clap_arg_matches.subcommand_name() {
|
||||
match self {
|
||||
|
|
Loading…
Reference in a new issue