Skip to content

Commit

Permalink
refactor(builder): Be more explicit in how takes_values is used
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2025
1 parent 67b74fb commit a8f9885
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 16 additions & 0 deletions clap_builder/src/builder/action.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(debug_assertions)]
use crate::util::AnyValueId;

use crate::builder::ValueRange;

/// Behavior of arguments when they are encountered while parsing
///
/// # Examples
Expand Down Expand Up @@ -369,6 +371,20 @@ impl ArgAction {
}
}

pub(crate) fn default_num_args(&self) -> ValueRange {
match self {
Self::Set => ValueRange::SINGLE,
Self::Append => ValueRange::SINGLE,
Self::SetTrue => ValueRange::EMPTY,
Self::SetFalse => ValueRange::EMPTY,
Self::Count => ValueRange::EMPTY,
Self::Help => ValueRange::EMPTY,
Self::HelpShort => ValueRange::EMPTY,
Self::HelpLong => ValueRange::EMPTY,
Self::Version => ValueRange::EMPTY,
}
}

pub(crate) fn default_value(&self) -> Option<&'static std::ffi::OsStr> {
match self {
Self::Set => None,
Expand Down
6 changes: 1 addition & 5 deletions clap_builder/src/builder/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4546,11 +4546,7 @@ impl Arg {
if val_names_len > 1 {
self.num_vals.get_or_insert(val_names_len.into());
} else {
let nargs = if self.get_action().takes_values() {
ValueRange::SINGLE
} else {
ValueRange::EMPTY
};
let nargs = self.get_action().default_num_args();
self.num_vals.get_or_insert(nargs);
}
}
Expand Down

0 comments on commit a8f9885

Please sign in to comment.