fix!: Remove deprecated ArgActions

This commit is contained in:
Ed Page 2022-07-22 13:36:10 -05:00
parent 122b562e6b
commit 50259e51d5
5 changed files with 8 additions and 157 deletions

View file

@ -216,19 +216,6 @@ fn gen_options(cmd: &Command, indent: usize) -> String {
buffer.push_str(&format!("{:indent$}],\n", "", indent = indent + 4));
}
#[allow(deprecated)]
if matches!(
option.get_action(),
ArgAction::StoreValue | ArgAction::IncOccurrence
) && option.is_multiple_occurrences_set()
{
buffer.push_str(&format!(
"{:indent$}isRepeatable: true,\n",
"",
indent = indent + 4
));
}
if let ArgAction::Set | ArgAction::Append | ArgAction::Count = option.get_action() {
buffer.push_str(&format!(
"{:indent$}isRepeatable: true,\n",
@ -316,19 +303,6 @@ fn gen_options(cmd: &Command, indent: usize) -> String {
buffer.push_str(&format!("{:indent$}],\n", "", indent = indent + 4));
}
#[allow(deprecated)]
if matches!(
flag.get_action(),
ArgAction::StoreValue | ArgAction::IncOccurrence
) && flag.is_multiple_occurrences_set()
{
buffer.push_str(&format!(
"{:indent$}isRepeatable: true,\n",
"",
indent = indent + 4
));
}
if let ArgAction::Set | ArgAction::Append | ArgAction::Count = flag.get_action() {
buffer.push_str(&format!(
"{:indent$}isRepeatable: true,\n",

View file

@ -70,24 +70,6 @@ pub enum ArgAction {
/// );
/// ```
Append,
/// Deprecated, replaced with [`ArgAction::Set`] or [`ArgAction::Append`]
#[cfg_attr(
feature = "deprecated",
deprecated(
since = "3.2.0",
note = "Replaced with `ArgAction::Set` or `ArgAction::Append`"
)
)]
StoreValue,
/// Deprecated, replaced with [`ArgAction::SetTrue`] or [`ArgAction::Count`]
#[cfg_attr(
feature = "deprecated",
deprecated(
since = "3.2.0",
note = "Replaced with `ArgAction::SetTrue` or `ArgAction::Count`"
)
)]
IncOccurrence,
/// When encountered, act as if `"true"` was encountered on the command-line
///
/// If no [`default_value`][super::Arg::default_value] is set, it will be `false`.
@ -258,10 +240,6 @@ impl ArgAction {
match self {
Self::Set => true,
Self::Append => true,
#[allow(deprecated)]
Self::StoreValue => true,
#[allow(deprecated)]
Self::IncOccurrence => false,
Self::SetTrue => false,
Self::SetFalse => false,
Self::Count => false,
@ -274,10 +252,6 @@ impl ArgAction {
match self {
Self::Set => None,
Self::Append => None,
#[allow(deprecated)]
Self::StoreValue => None,
#[allow(deprecated)]
Self::IncOccurrence => None,
Self::SetTrue => Some(std::ffi::OsStr::new("false")),
Self::SetFalse => Some(std::ffi::OsStr::new("true")),
Self::Count => Some(std::ffi::OsStr::new("0")),
@ -290,10 +264,6 @@ impl ArgAction {
match self {
Self::Set => None,
Self::Append => None,
#[allow(deprecated)]
Self::StoreValue => None,
#[allow(deprecated)]
Self::IncOccurrence => None,
Self::SetTrue => Some(super::ValueParser::bool()),
Self::SetFalse => Some(super::ValueParser::bool()),
Self::Count => Some(crate::value_parser!(u8).into()),
@ -309,10 +279,6 @@ impl ArgAction {
match self {
Self::Set => None,
Self::Append => None,
#[allow(deprecated)]
Self::StoreValue => None,
#[allow(deprecated)]
Self::IncOccurrence => None,
Self::SetTrue => Some(AnyValueId::of::<bool>()),
Self::SetFalse => Some(AnyValueId::of::<bool>()),
Self::Count => Some(AnyValueId::of::<CountType>()),

View file

@ -4400,10 +4400,7 @@ impl<'help> Arg<'help> {
self.settings.unset(ArgSettings::TakesValue);
}
match action {
ArgAction::StoreValue
| ArgAction::IncOccurrence
| ArgAction::Help
| ArgAction::Version => {}
ArgAction::Help | ArgAction::Version => {}
ArgAction::Set
| ArgAction::Append
| ArgAction::SetTrue

View file

@ -72,11 +72,6 @@ impl MatchedArg {
self.occurs += 1;
}
#[cfg_attr(feature = "deprecated", deprecated(since = "3.2.0"))]
pub(crate) fn set_occurrences(&mut self, occurs: u64) {
self.occurs = occurs
}
#[cfg_attr(feature = "deprecated", deprecated(since = "3.2.0"))]
pub(crate) fn get_occurrences(&self) -> u64 {
self.occurs

View file

@ -1180,53 +1180,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
}
Ok(ParseResult::ValuesDone)
}
#[allow(deprecated)]
ArgAction::StoreValue => {
if ident == Some(Identifier::Index)
&& arg.is_multiple_values_set()
&& matcher.contains(&arg.id)
{
// HACK: Reuse existing occurrence
} else if source == ValueSource::CommandLine {
if matches!(ident, Some(Identifier::Short) | Some(Identifier::Long)) {
// Record flag's index
self.cur_idx.set(self.cur_idx.get() + 1);
debug!("Parser::react: cur_idx:={}", self.cur_idx.get());
}
self.start_occurrence_of_arg(matcher, arg);
} else {
self.start_custom_arg(matcher, arg, source);
}
self.push_arg_values(arg, raw_vals, matcher)?;
if ident == Some(Identifier::Index) && arg.is_multiple_values_set() {
// HACK: Maintain existing occurrence behavior
let matched = matcher.get_mut(&arg.id).unwrap();
#[allow(deprecated)]
matched.set_occurrences(matched.num_vals() as u64);
}
if cfg!(debug_assertions) && matcher.needs_more_vals(arg) {
debug!(
"Parser::react not enough values passed in, leaving it to the validator to complain",
);
}
Ok(ParseResult::ValuesDone)
}
#[allow(deprecated)]
ArgAction::IncOccurrence => {
debug_assert_eq!(raw_vals, Vec::<OsString>::new());
if source == ValueSource::CommandLine {
if matches!(ident, Some(Identifier::Short) | Some(Identifier::Long)) {
// Record flag's index
self.cur_idx.set(self.cur_idx.get() + 1);
debug!("Parser::react: cur_idx:={}", self.cur_idx.get());
}
self.start_occurrence_of_arg(matcher, arg);
} else {
self.start_custom_arg(matcher, arg, source);
}
matcher.add_index_to(&arg.id, self.cur_idx.get());
Ok(ParseResult::ValuesDone)
}
ArgAction::SetTrue => {
let raw_vals = match raw_vals.len() {
0 => {
@ -1338,7 +1291,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
#[cfg(feature = "env")]
fn add_env(&mut self, matcher: &mut ArgMatcher) -> ClapResult<()> {
debug!("Parser::add_env");
use crate::util::str_to_bool;
let trailing_values = false; // defaults are independent of the commandline
for arg in self.cmd.get_arguments() {
@ -1368,46 +1320,13 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
}
}
} else {
match arg.get_action() {
#[allow(deprecated)]
ArgAction::StoreValue => unreachable!("{:?} is not a flag", arg.get_id()),
#[allow(deprecated)]
ArgAction::IncOccurrence => {
debug!("Parser::add_env: Found a flag with value `{:?}`", val);
let predicate = str_to_bool(val.to_str_lossy());
debug!("Parser::add_env: Found boolean literal `{:?}`", predicate);
if predicate.unwrap_or(true) {
let _ = self.react(
None,
ValueSource::EnvVariable,
arg,
vec![],
matcher,
)?;
}
}
ArgAction::Set
| ArgAction::Append
| ArgAction::SetTrue
| ArgAction::SetFalse
| ArgAction::Count
| ArgAction::Help
| ArgAction::Version => {
let mut arg_values = Vec::new();
let _parse_result =
self.split_arg_values(arg, &val, trailing_values, &mut arg_values);
let _ = self.react(
None,
ValueSource::EnvVariable,
arg,
arg_values,
matcher,
)?;
if let Some(_parse_result) = _parse_result {
if _parse_result != ParseResult::ValuesDone {
debug!("Parser::add_env: Ignoring state {:?}; env variables are outside of the parse loop", _parse_result);
}
}
let mut arg_values = Vec::new();
let _parse_result =
self.split_arg_values(arg, &val, trailing_values, &mut arg_values);
let _ = self.react(None, ValueSource::EnvVariable, arg, arg_values, matcher)?;
if let Some(_parse_result) = _parse_result {
if _parse_result != ParseResult::ValuesDone {
debug!("Parser::add_env: Ignoring state {:?}; env variables are outside of the parse loop", _parse_result);
}
}
}