mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
fix!: Remove lifetime from PossibleValue
Another step towards #1041 This isn't the long term type for `PossibleValue::help`, I just wanted to get the lifetime out of the way first before figuring out how help will work.
This commit is contained in:
parent
99d3bb8f74
commit
8cc164dafb
22 changed files with 104 additions and 92 deletions
|
@ -231,7 +231,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
|
|||
Self::Menu,
|
||||
]
|
||||
}
|
||||
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue<'a>> {
|
||||
fn to_possible_value(&self) -> ::std::option::Option<clap::builder::PossibleValue> {
|
||||
match self {
|
||||
Self::Normal => {
|
||||
let value = "9";
|
||||
|
|
|
@ -127,7 +127,7 @@ pub fn flags<'help>(p: &Command<'help>) -> Vec<Arg<'help>> {
|
|||
}
|
||||
|
||||
/// Get the possible values for completion
|
||||
pub fn possible_values<'help>(a: &Arg<'help>) -> Option<Vec<clap::builder::PossibleValue<'help>>> {
|
||||
pub fn possible_values(a: &Arg<'_>) -> Option<Vec<clap::builder::PossibleValue>> {
|
||||
if !a.get_num_args().expect("built").takes_values() {
|
||||
None
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::{fmt::Write as _, io::Write};
|
||||
|
||||
use clap::builder::PossibleValue;
|
||||
use clap::*;
|
||||
|
||||
use crate::generator::{utils, Generator};
|
||||
|
@ -180,7 +179,7 @@ fn vals_for(o: &Arg) -> String {
|
|||
"$(compgen -W \"{}\" -- \"${{cur}}\")",
|
||||
vals.iter()
|
||||
.filter(|pv| !pv.is_hide_set())
|
||||
.map(PossibleValue::get_name)
|
||||
.map(|n| n.get_name().as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
)
|
||||
|
|
|
@ -164,7 +164,8 @@ fn value_completion(option: &Arg) -> String {
|
|||
Some(format!(
|
||||
"{}\t{}",
|
||||
escape_string(value.get_name()).as_str(),
|
||||
escape_string(value.get_help().unwrap_or_default()).as_str()
|
||||
escape_string(value.get_help().map(|s| s.as_str()).unwrap_or_default())
|
||||
.as_str()
|
||||
))
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
|
|
|
@ -57,7 +57,7 @@ impl ValueEnum for Shell {
|
|||
]
|
||||
}
|
||||
|
||||
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>> {
|
||||
fn to_possible_value<'a>(&self) -> Option<PossibleValue> {
|
||||
Some(match self {
|
||||
Shell::Bash => PossibleValue::new("bash"),
|
||||
Shell::Elvish => PossibleValue::new("elvish"),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::io::Write;
|
||||
|
||||
use clap::builder::PossibleValue;
|
||||
use clap::*;
|
||||
|
||||
use crate::generator::{utils, Generator};
|
||||
|
@ -375,8 +374,12 @@ fn value_completion(arg: &Arg) -> Option<String> {
|
|||
} else {
|
||||
Some(format!(
|
||||
r#"{name}\:"{tooltip}""#,
|
||||
name = escape_value(value.get_name()),
|
||||
tooltip = value.get_help().map(escape_help).unwrap_or_default()
|
||||
name = escape_value(value.get_name().as_str()),
|
||||
tooltip = value
|
||||
.get_help()
|
||||
.map(|s| s.as_str())
|
||||
.map(escape_help)
|
||||
.unwrap_or_default()
|
||||
))
|
||||
}
|
||||
})
|
||||
|
@ -389,7 +392,7 @@ fn value_completion(arg: &Arg) -> Option<String> {
|
|||
values
|
||||
.iter()
|
||||
.filter(|pv| !pv.is_hide_set())
|
||||
.map(PossibleValue::get_name)
|
||||
.map(|n| n.get_name().as_str())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
))
|
||||
|
|
|
@ -499,7 +499,7 @@ impl Attrs {
|
|||
quote_spanned!(ident.span()=> {
|
||||
{
|
||||
let val: #ty = #val;
|
||||
clap::ValueEnum::to_possible_value(&val).unwrap().get_name()
|
||||
clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -544,17 +544,15 @@ impl Attrs {
|
|||
let val = if parsed.iter().any(|a| matches!(a, ValueEnum(_))) {
|
||||
quote_spanned!(ident.span()=> {
|
||||
{
|
||||
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> Vec<&'static str>
|
||||
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=clap::Str>
|
||||
where
|
||||
T: ::std::borrow::Borrow<#inner_type>
|
||||
{
|
||||
iterable
|
||||
.into_iter()
|
||||
.map(|val| {
|
||||
clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name()
|
||||
clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name().to_owned()
|
||||
})
|
||||
.collect()
|
||||
|
||||
}
|
||||
|
||||
iter_to_vals(#expr)
|
||||
|
@ -603,7 +601,7 @@ impl Attrs {
|
|||
quote_spanned!(ident.span()=> {
|
||||
{
|
||||
let val: #ty = #val;
|
||||
clap::ValueEnum::to_possible_value(&val).unwrap().get_name()
|
||||
clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -648,18 +646,15 @@ impl Attrs {
|
|||
let val = if parsed.iter().any(|a| matches!(a, ValueEnum(_))) {
|
||||
quote_spanned!(ident.span()=> {
|
||||
{
|
||||
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> Vec<&'static ::std::ffi::OsStr>
|
||||
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=clap::Str>
|
||||
where
|
||||
T: ::std::borrow::Borrow<#inner_type>
|
||||
{
|
||||
iterable
|
||||
.into_iter()
|
||||
.map(|val| {
|
||||
clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name()
|
||||
clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name().to_owned()
|
||||
})
|
||||
.map(::std::ffi::OsStr::new)
|
||||
.collect()
|
||||
|
||||
}
|
||||
|
||||
iter_to_vals(#expr)
|
||||
|
|
|
@ -114,7 +114,7 @@ fn gen_to_possible_value(lits: &[(TokenStream, Ident)]) -> TokenStream {
|
|||
let (lit, variant): (Vec<TokenStream>, Vec<Ident>) = lits.iter().cloned().unzip();
|
||||
|
||||
quote! {
|
||||
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue<'a>> {
|
||||
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue> {
|
||||
match self {
|
||||
#(Self::#variant => Some(#lit),)*
|
||||
_ => None
|
||||
|
|
|
@ -82,7 +82,7 @@ pub fn value_enum(name: &Ident) {
|
|||
fn from_str(_input: &str, _ignore_case: bool) -> ::std::result::Result<Self, String> {
|
||||
unimplemented!()
|
||||
}
|
||||
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue<'a>>{
|
||||
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue>{
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ impl ValueEnum for Mode {
|
|||
&[Mode::Fast, Mode::Slow]
|
||||
}
|
||||
|
||||
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>> {
|
||||
fn to_possible_value<'a>(&self) -> Option<PossibleValue> {
|
||||
Some(match self {
|
||||
Mode::Fast => PossibleValue::new("fast"),
|
||||
Mode::Slow => PossibleValue::new("slow"),
|
||||
|
|
|
@ -3659,7 +3659,7 @@ impl<'help> Arg<'help> {
|
|||
Some(longs)
|
||||
}
|
||||
|
||||
pub(crate) fn get_possible_values(&self) -> Vec<PossibleValue<'help>> {
|
||||
pub(crate) fn get_possible_values(&self) -> Vec<PossibleValue> {
|
||||
if !self.is_takes_value_set() {
|
||||
vec![]
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{borrow::Cow, iter};
|
||||
|
||||
use crate::util::eq_ignore_case;
|
||||
use crate::Str;
|
||||
|
||||
/// A possible value of an argument.
|
||||
///
|
||||
|
@ -27,14 +28,14 @@ use crate::util::eq_ignore_case;
|
|||
/// [hide]: PossibleValue::hide()
|
||||
/// [help]: PossibleValue::help()
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct PossibleValue<'help> {
|
||||
name: &'help str,
|
||||
help: Option<&'help str>,
|
||||
aliases: Vec<&'help str>, // (name, visible)
|
||||
pub struct PossibleValue {
|
||||
name: Str,
|
||||
help: Option<Str>,
|
||||
aliases: Vec<Str>, // (name, visible)
|
||||
hide: bool,
|
||||
}
|
||||
|
||||
impl<'help> PossibleValue<'help> {
|
||||
impl PossibleValue {
|
||||
/// Create a [`PossibleValue`] with its name.
|
||||
///
|
||||
/// The name will be used to decide whether this value was provided by the user to an argument.
|
||||
|
@ -52,9 +53,9 @@ impl<'help> PossibleValue<'help> {
|
|||
/// [hidden]: PossibleValue::hide
|
||||
/// [possible value]: crate::builder::PossibleValuesParser
|
||||
/// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values()
|
||||
pub fn new(name: &'help str) -> Self {
|
||||
pub fn new(name: impl Into<Str>) -> Self {
|
||||
PossibleValue {
|
||||
name,
|
||||
name: name.into(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +75,8 @@ impl<'help> PossibleValue<'help> {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn help(mut self, help: &'help str) -> Self {
|
||||
self.help = Some(help);
|
||||
pub fn help(mut self, help: impl Into<Str>) -> Self {
|
||||
self.help = Some(help.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -111,8 +112,8 @@ impl<'help> PossibleValue<'help> {
|
|||
/// # ;
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn alias(mut self, name: &'help str) -> Self {
|
||||
self.aliases.push(name);
|
||||
pub fn alias(mut self, name: impl Into<Str>) -> Self {
|
||||
self.aliases.push(name.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -127,35 +128,32 @@ impl<'help> PossibleValue<'help> {
|
|||
/// # ;
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn aliases<I>(mut self, names: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = &'help str>,
|
||||
{
|
||||
self.aliases.extend(names.into_iter());
|
||||
pub fn aliases(mut self, names: impl IntoIterator<Item = impl Into<Str>>) -> Self {
|
||||
self.aliases.extend(names.into_iter().map(|a| a.into()));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Reflection
|
||||
impl<'help> PossibleValue<'help> {
|
||||
impl PossibleValue {
|
||||
/// Get the name of the argument value
|
||||
#[inline]
|
||||
pub fn get_name(&self) -> &'help str {
|
||||
self.name
|
||||
pub fn get_name(&self) -> &Str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// Get the help specified for this argument, if any
|
||||
#[inline]
|
||||
pub fn get_help(&self) -> Option<&'help str> {
|
||||
self.help
|
||||
pub fn get_help(&self) -> Option<&Str> {
|
||||
self.help.as_ref()
|
||||
}
|
||||
|
||||
/// Get the help specified for this argument, if any and the argument
|
||||
/// value is not hidden
|
||||
#[inline]
|
||||
pub(crate) fn get_visible_help(&self) -> Option<&'help str> {
|
||||
pub(crate) fn get_visible_help(&self) -> Option<&str> {
|
||||
if !self.hide {
|
||||
self.help
|
||||
self.help.as_deref()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -174,12 +172,12 @@ impl<'help> PossibleValue<'help> {
|
|||
|
||||
/// Get the name if argument value is not hidden, `None` otherwise,
|
||||
/// but wrapped in quotes if it contains whitespace
|
||||
pub(crate) fn get_visible_quoted_name(&self) -> Option<Cow<'help, str>> {
|
||||
pub(crate) fn get_visible_quoted_name(&self) -> Option<Cow<'_, str>> {
|
||||
if !self.hide {
|
||||
Some(if self.name.contains(char::is_whitespace) {
|
||||
format!("{:?}", self.name).into()
|
||||
} else {
|
||||
self.name.into()
|
||||
self.name.as_str().into()
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
@ -189,8 +187,8 @@ impl<'help> PossibleValue<'help> {
|
|||
/// Returns all valid values of the argument value.
|
||||
///
|
||||
/// Namely the name and all aliases.
|
||||
pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &'help str> + '_ {
|
||||
iter::once(&self.name).chain(&self.aliases).copied()
|
||||
pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &Str> + '_ {
|
||||
iter::once(&self.name).chain(self.aliases.iter())
|
||||
}
|
||||
|
||||
/// Tests if the value is valid for this argument value
|
||||
|
@ -212,21 +210,15 @@ impl<'help> PossibleValue<'help> {
|
|||
pub fn matches(&self, value: &str, ignore_case: bool) -> bool {
|
||||
if ignore_case {
|
||||
self.get_name_and_aliases()
|
||||
.any(|name| eq_ignore_case(name, value))
|
||||
.any(|name| eq_ignore_case(name.as_str(), value))
|
||||
} else {
|
||||
self.get_name_and_aliases().any(|name| name == value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'help> From<&'help str> for PossibleValue<'help> {
|
||||
fn from(s: &'help str) -> Self {
|
||||
Self::new(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'help> From<&'_ &'help str> for PossibleValue<'help> {
|
||||
fn from(s: &'_ &'help str) -> Self {
|
||||
impl<S: Into<Str>> From<S> for PossibleValue {
|
||||
fn from(s: S) -> Self {
|
||||
Self::new(s)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -243,7 +243,7 @@ impl ValueParser {
|
|||
/// applications like errors and completion.
|
||||
pub fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
self.any_value_parser().possible_values()
|
||||
}
|
||||
|
||||
|
@ -501,7 +501,7 @@ impl From<std::ops::RangeFull> for ValueParser {
|
|||
/// ```
|
||||
impl<P, const C: usize> From<[P; C]> for ValueParser
|
||||
where
|
||||
P: Into<super::PossibleValue<'static>>,
|
||||
P: Into<super::PossibleValue>,
|
||||
{
|
||||
fn from(values: [P; C]) -> Self {
|
||||
let inner = PossibleValuesParser::from(values);
|
||||
|
@ -554,7 +554,7 @@ trait AnyValueParser: Send + Sync + 'static {
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>>;
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>>;
|
||||
|
||||
fn clone_any(&self) -> Box<dyn AnyValueParser>;
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ where
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
P::possible_values(self)
|
||||
}
|
||||
|
||||
|
@ -632,7 +632,7 @@ pub trait TypedValueParser: Clone + Send + Sync + 'static {
|
|||
/// applications like errors and completion.
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -876,7 +876,7 @@ impl Default for PathBufValueParser {
|
|||
/// &[Self::Always, Self::Auto, Self::Never]
|
||||
/// }
|
||||
///
|
||||
/// fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue<'a>> {
|
||||
/// fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue> {
|
||||
/// match self {
|
||||
/// Self::Always => Some(clap::builder::PossibleValue::new("always")),
|
||||
/// Self::Auto => Some(clap::builder::PossibleValue::new("auto")),
|
||||
|
@ -936,7 +936,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> TypedValueParser for E
|
|||
.iter()
|
||||
.filter_map(|v| v.to_possible_value())
|
||||
.filter(|v| !v.is_hide_set())
|
||||
.map(|v| v.get_name())
|
||||
.map(|v| v.get_name().as_str().to_owned())
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
|
@ -971,7 +971,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> TypedValueParser for E
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
Some(Box::new(
|
||||
E::value_variants()
|
||||
.iter()
|
||||
|
@ -1022,7 +1022,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> Default for EnumValueP
|
|||
/// assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("never")).unwrap(), "never");
|
||||
/// ```
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PossibleValuesParser(Vec<super::PossibleValue<'static>>);
|
||||
pub struct PossibleValuesParser(Vec<super::PossibleValue>);
|
||||
|
||||
impl PossibleValuesParser {
|
||||
/// Verify the value is from an enumerated set pf [`PossibleValue`][crate::builder::PossibleValue].
|
||||
|
@ -1064,7 +1064,7 @@ impl TypedValueParser for PossibleValuesParser {
|
|||
.0
|
||||
.iter()
|
||||
.filter(|v| !v.is_hide_set())
|
||||
.map(crate::builder::PossibleValue::get_name)
|
||||
.map(|v| v.get_name().as_str().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Err(crate::Error::invalid_value(
|
||||
|
@ -1079,7 +1079,7 @@ impl TypedValueParser for PossibleValuesParser {
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
Some(Box::new(self.0.iter().cloned()))
|
||||
}
|
||||
}
|
||||
|
@ -1087,7 +1087,7 @@ impl TypedValueParser for PossibleValuesParser {
|
|||
impl<I, T> From<I> for PossibleValuesParser
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<super::PossibleValue<'static>>,
|
||||
T: Into<super::PossibleValue>,
|
||||
{
|
||||
fn from(values: I) -> Self {
|
||||
Self(values.into_iter().map(|t| t.into()).collect())
|
||||
|
@ -1501,7 +1501,7 @@ impl BoolValueParser {
|
|||
Self {}
|
||||
}
|
||||
|
||||
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue<'static>> {
|
||||
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue> {
|
||||
["true", "false"]
|
||||
.iter()
|
||||
.copied()
|
||||
|
@ -1525,7 +1525,7 @@ impl TypedValueParser for BoolValueParser {
|
|||
} else {
|
||||
// Intentionally showing hidden as we hide all of them
|
||||
let possible_vals = Self::possible_values()
|
||||
.map(|v| v.get_name())
|
||||
.map(|v| v.get_name().as_str().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
return Err(crate::Error::invalid_value(
|
||||
|
@ -1541,7 +1541,7 @@ impl TypedValueParser for BoolValueParser {
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
Some(Box::new(Self::possible_values()))
|
||||
}
|
||||
}
|
||||
|
@ -1600,7 +1600,7 @@ impl FalseyValueParser {
|
|||
Self {}
|
||||
}
|
||||
|
||||
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue<'static>> {
|
||||
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue> {
|
||||
crate::util::TRUE_LITERALS
|
||||
.iter()
|
||||
.chain(crate::util::FALSE_LITERALS.iter())
|
||||
|
@ -1634,7 +1634,7 @@ impl TypedValueParser for FalseyValueParser {
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
Some(Box::new(Self::possible_values()))
|
||||
}
|
||||
}
|
||||
|
@ -1697,7 +1697,7 @@ impl BoolishValueParser {
|
|||
Self {}
|
||||
}
|
||||
|
||||
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue<'static>> {
|
||||
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue> {
|
||||
crate::util::TRUE_LITERALS
|
||||
.iter()
|
||||
.chain(crate::util::FALSE_LITERALS.iter())
|
||||
|
@ -1733,7 +1733,7 @@ impl TypedValueParser for BoolishValueParser {
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
Some(Box::new(Self::possible_values()))
|
||||
}
|
||||
}
|
||||
|
@ -1874,7 +1874,7 @@ where
|
|||
|
||||
fn possible_values(
|
||||
&self,
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
|
||||
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue> + '_>> {
|
||||
self.parser.possible_values()
|
||||
}
|
||||
}
|
||||
|
@ -2130,7 +2130,7 @@ pub mod via_prelude {
|
|||
/// # fn value_variants<'a>() -> &'a [Self] {
|
||||
/// # &[Self::Always, Self::Auto, Self::Never]
|
||||
/// # }
|
||||
/// # fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue<'a>> {
|
||||
/// # fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue> {
|
||||
/// # match self {
|
||||
/// # Self::Always => Some(clap::builder::PossibleValue::new("always")),
|
||||
/// # Self::Auto => Some(clap::builder::PossibleValue::new("auto")),
|
||||
|
|
|
@ -387,7 +387,7 @@ pub trait ValueEnum: Sized + Clone {
|
|||
/// The canonical argument value.
|
||||
///
|
||||
/// The value is `None` for skipped variants.
|
||||
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>>;
|
||||
fn to_possible_value(&self) -> Option<PossibleValue>;
|
||||
}
|
||||
|
||||
impl<T: Parser> Parser for Box<T> {
|
||||
|
|
|
@ -243,7 +243,7 @@ impl Error {
|
|||
])
|
||||
}
|
||||
|
||||
pub(crate) fn empty_value(cmd: &Command, good_vals: &[&str], arg: String) -> Self {
|
||||
pub(crate) fn empty_value(cmd: &Command, good_vals: &[String], arg: String) -> Self {
|
||||
Self::invalid_value(cmd, "".to_owned(), good_vals, arg)
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ impl Error {
|
|||
pub(crate) fn invalid_value(
|
||||
cmd: &Command,
|
||||
bad_val: String,
|
||||
good_vals: &[&str],
|
||||
good_vals: &[String],
|
||||
arg: String,
|
||||
) -> Self {
|
||||
let suggestion = suggestions::did_you_mean(&bad_val, good_vals.iter()).pop();
|
||||
|
|
|
@ -110,7 +110,7 @@ pub use crate::util::color::ColorChoice;
|
|||
pub(crate) use crate::util::color::ColorChoice;
|
||||
pub use crate::util::Id;
|
||||
pub use crate::util::OsStr;
|
||||
pub(crate) use crate::util::Str;
|
||||
pub use crate::util::Str;
|
||||
|
||||
pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum};
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> {
|
|||
self.none("\n")?;
|
||||
self.spaces(spaces)?;
|
||||
self.none("- ")?;
|
||||
self.good(pv.get_name())?;
|
||||
self.good(pv.get_name().as_str())?;
|
||||
if let Some(help) = pv.get_help() {
|
||||
debug!("Help::help: Possible Value help");
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ use clap_lex::RawOsStr;
|
|||
use clap_lex::RawOsString;
|
||||
|
||||
// Internal
|
||||
use crate::builder::PossibleValue;
|
||||
use crate::builder::{Arg, Command};
|
||||
use crate::error::Error as ClapError;
|
||||
use crate::error::Result as ClapResult;
|
||||
|
@ -1266,7 +1265,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
|
|||
&super::get_possible_values_cli(arg)
|
||||
.iter()
|
||||
.filter(|pv| !pv.is_hide_set())
|
||||
.map(PossibleValue::get_name)
|
||||
.map(|n| n.get_name().as_str().to_owned())
|
||||
.collect::<Vec<_>>(),
|
||||
arg.to_string(),
|
||||
));
|
||||
|
|
|
@ -45,7 +45,7 @@ impl<'help, 'cmd> Validator<'help, 'cmd> {
|
|||
&get_possible_values_cli(o)
|
||||
.iter()
|
||||
.filter(|pv| !pv.is_hide_set())
|
||||
.map(PossibleValue::get_name)
|
||||
.map(|n| n.get_name().as_str().to_owned())
|
||||
.collect::<Vec<_>>(),
|
||||
o.to_string(),
|
||||
));
|
||||
|
@ -455,7 +455,7 @@ impl Conflicts {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_possible_values_cli<'help>(a: &Arg<'help>) -> Vec<PossibleValue<'help>> {
|
||||
pub(crate) fn get_possible_values_cli(a: &Arg<'_>) -> Vec<PossibleValue> {
|
||||
if !a.is_takes_value_set() {
|
||||
vec![]
|
||||
} else {
|
||||
|
|
|
@ -16,6 +16,7 @@ pub(crate) use self::flat_map::Entry;
|
|||
pub(crate) use self::flat_map::FlatMap;
|
||||
pub(crate) use self::flat_set::FlatSet;
|
||||
pub(crate) use self::graph::ChildGraph;
|
||||
pub(crate) use self::str::Inner as StrInner;
|
||||
pub(crate) use self::str_to_bool::str_to_bool;
|
||||
pub(crate) use self::str_to_bool::FALSE_LITERALS;
|
||||
pub(crate) use self::str_to_bool::TRUE_LITERALS;
|
||||
|
|
|
@ -40,6 +40,24 @@ impl From<&'_ OsStr> for OsStr {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<crate::Str> for OsStr {
|
||||
fn from(id: crate::Str) -> Self {
|
||||
match id.into_inner() {
|
||||
crate::util::StrInner::Static(s) => Self::from_static_ref(std::ffi::OsStr::new(s)),
|
||||
crate::util::StrInner::Owned(s) => Self::from_ref(std::ffi::OsStr::new(s.as_ref())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'_ crate::Str> for OsStr {
|
||||
fn from(id: &'_ crate::Str) -> Self {
|
||||
match id.clone().into_inner() {
|
||||
crate::util::StrInner::Static(s) => Self::from_static_ref(std::ffi::OsStr::new(s)),
|
||||
crate::util::StrInner::Owned(s) => Self::from_ref(std::ffi::OsStr::new(s.as_ref())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::ffi::OsString> for OsStr {
|
||||
fn from(name: std::ffi::OsString) -> Self {
|
||||
Self::from_string(name)
|
||||
|
|
|
@ -23,6 +23,10 @@ impl Str {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn into_inner(self) -> Inner {
|
||||
self.name
|
||||
}
|
||||
|
||||
/// Get the raw string of the `Str`
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.name.as_str()
|
||||
|
@ -139,7 +143,7 @@ impl PartialEq<std::string::String> for Str {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum Inner {
|
||||
pub(crate) enum Inner {
|
||||
Static(&'static str),
|
||||
Owned(Box<str>),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue