Skip to content

Commit cc6efc0

Browse files
committed
fix!: Rename ArgValue to PossibleValue
In considering potential work for clap-rs#2683, I realized we might need a type to carry data for each of the `multiple_values`. `ArgValue` works both for that and for possible values, so we need to come up with a better name for one or both. Changing `ArgValue`s name now would be ideal since its new in clap3 and by renaming it, we can reduce churn for users. While thinking about this, I realized I regularly get these mixed up, so renaming `ArgValue` to `PossibleValue` I think will help clear things up, regardless of clap-rs#2683.
1 parent 33d86ef commit cc6efc0

File tree

17 files changed

+90
-90
lines changed

17 files changed

+90
-90
lines changed

clap_derive/src/derives/arg_enum.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
4747
);
4848

4949
let lits = lits(&e.variants, &attrs);
50-
let arg_values = gen_arg_values(&lits);
51-
let to_arg_value = gen_to_arg_value(&lits);
50+
let value_variants = gen_value_variants(&lits);
51+
let to_possible_value = gen_to_possible_value(&lits);
5252

5353
quote! {
5454
#[allow(dead_code, unreachable_code, unused_variables)]
@@ -64,8 +64,8 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
6464
)]
6565
#[deny(clippy::correctness)]
6666
impl clap::ArgEnum for #name {
67-
#arg_values
68-
#to_arg_value
67+
#value_variants
68+
#to_possible_value
6969
}
7070
}
7171
}
@@ -89,7 +89,7 @@ fn lits(
8989
let name = attrs.cased_name();
9090
Some((
9191
quote! {
92-
clap::ArgValue::new(#name)
92+
clap::PossibleValue::new(#name)
9393
#fields
9494
},
9595
variant.ident.clone(),
@@ -99,7 +99,7 @@ fn lits(
9999
.collect::<Vec<_>>()
100100
}
101101

102-
fn gen_arg_values(lits: &[(TokenStream, Ident)]) -> TokenStream {
102+
fn gen_value_variants(lits: &[(TokenStream, Ident)]) -> TokenStream {
103103
let lit = lits.iter().map(|l| &l.1).collect::<Vec<_>>();
104104

105105
quote! {
@@ -109,11 +109,11 @@ fn gen_arg_values(lits: &[(TokenStream, Ident)]) -> TokenStream {
109109
}
110110
}
111111

112-
fn gen_to_arg_value(lits: &[(TokenStream, Ident)]) -> TokenStream {
112+
fn gen_to_possible_value(lits: &[(TokenStream, Ident)]) -> TokenStream {
113113
let (lit, variant): (Vec<TokenStream>, Vec<Ident>) = lits.iter().cloned().unzip();
114114

115115
quote! {
116-
fn to_arg_value<'a>(&self) -> Option<clap::ArgValue<'a>> {
116+
fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>> {
117117
match self {
118118
#(Self::#variant => Some(#lit),)*
119119
_ => None

clap_derive/src/derives/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pub fn gen_augment(
372372

373373
fn gen_arg_enum_possible_values(ty: &Type) -> TokenStream {
374374
quote_spanned! { ty.span()=>
375-
.possible_values(<#ty as clap::ArgEnum>::value_variants().iter().filter_map(clap::ArgEnum::to_arg_value))
375+
.possible_values(<#ty as clap::ArgEnum>::value_variants().iter().filter_map(clap::ArgEnum::to_possible_value))
376376
}
377377
}
378378

clap_derive/src/dummies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn arg_enum(name: &Ident) {
8282
fn from_str(_input: &str, _case_insensitive: bool) -> Result<Self, String> {
8383
unimplemented!()
8484
}
85-
fn to_arg_value<'a>(&self) -> Option<clap::ArgValue<'a>>{
85+
fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>>{
8686
unimplemented!()
8787
}
8888
}

clap_derive/tests/arg_enum.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
use clap::{ArgEnum, ArgValue, Parser};
10+
use clap::{ArgEnum, Parser, PossibleValue};
1111

1212
#[test]
1313
fn basic() {
@@ -54,7 +54,7 @@ fn default_value() {
5454

5555
impl std::fmt::Display for ArgChoice {
5656
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
57-
std::fmt::Display::fmt(self.to_arg_value().unwrap().get_name(), f)
57+
std::fmt::Display::fmt(self.to_possible_value().unwrap().get_name(), f)
5858
}
5959
}
6060

@@ -370,10 +370,10 @@ fn skip_variant() {
370370
assert_eq!(
371371
ArgChoice::value_variants()
372372
.iter()
373-
.map(ArgEnum::to_arg_value)
373+
.map(ArgEnum::to_possible_value)
374374
.map(Option::unwrap)
375375
.collect::<Vec<_>>(),
376-
vec![ArgValue::new("foo"), ArgValue::new("bar")]
376+
vec![PossibleValue::new("foo"), PossibleValue::new("bar")]
377377
);
378378
assert!(ArgChoice::from_str("foo", true).is_ok());
379379
assert!(ArgChoice::from_str("bar", true).is_ok());

clap_generate/examples/value_hints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn build_cli() -> App<'static> {
2323
.arg(
2424
Arg::new("generator")
2525
.long("generate")
26-
.possible_values(Shell::arg_values()),
26+
.possible_values(Shell::possible_values()),
2727
)
2828
.arg(
2929
Arg::new("unknown")

clap_generate/src/generators/shells/bash.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn vals_for(o: &Arg) -> String {
179179
format!(
180180
"$(compgen -W \"{}\" -- \"${{cur}}\")",
181181
vals.iter()
182-
.filter_map(ArgValue::get_visible_name)
182+
.filter_map(PossibleValue::get_visible_name)
183183
.collect::<Vec<_>>()
184184
.join(" ")
185185
)

clap_generate/src/generators/shells/zsh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ fn value_completion(arg: &Arg) -> Option<String> {
372372
"({})",
373373
values
374374
.iter()
375-
.filter_map(ArgValue::get_visible_name)
375+
.filter_map(PossibleValue::get_visible_name)
376376
.collect::<Vec<_>>()
377377
.join(" ")
378378
))

clap_generate/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//! .arg(
3737
//! Arg::new("generator")
3838
//! .long("generate")
39-
//! .possible_values(Shell::arg_values()),
39+
//! .possible_values(Shell::possible_values()),
4040
//! )
4141
//! }
4242
//!

clap_generate/src/shell.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Display;
22
use std::str::FromStr;
33

4-
use clap::{ArgEnum, ArgValue};
4+
use clap::{ArgEnum, PossibleValue};
55

66
use crate::{generators, Generator};
77

@@ -23,16 +23,16 @@ pub enum Shell {
2323

2424
impl Shell {
2525
/// Report all `possible_values`
26-
pub fn arg_values() -> impl Iterator<Item = ArgValue<'static>> {
26+
pub fn possible_values() -> impl Iterator<Item = PossibleValue<'static>> {
2727
Shell::value_variants()
2828
.iter()
29-
.filter_map(ArgEnum::to_arg_value)
29+
.filter_map(ArgEnum::to_possible_value)
3030
}
3131
}
3232

3333
impl Display for Shell {
3434
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35-
self.to_arg_value()
35+
self.to_possible_value()
3636
.expect("no values are skipped")
3737
.get_name()
3838
.fmt(f)
@@ -44,7 +44,7 @@ impl FromStr for Shell {
4444

4545
fn from_str(s: &str) -> Result<Self, Self::Err> {
4646
for variant in Self::value_variants() {
47-
if variant.to_arg_value().unwrap().matches(s, false) {
47+
if variant.to_possible_value().unwrap().matches(s, false) {
4848
return Ok(*variant);
4949
}
5050
}
@@ -64,13 +64,13 @@ impl ArgEnum for Shell {
6464
]
6565
}
6666

67-
fn to_arg_value<'a>(&self) -> Option<ArgValue<'a>> {
67+
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>> {
6868
Some(match self {
69-
Shell::Bash => ArgValue::new("bash"),
70-
Shell::Elvish => ArgValue::new("elvish"),
71-
Shell::Fish => ArgValue::new("fish"),
72-
Shell::PowerShell => ArgValue::new("powershell"),
73-
Shell::Zsh => ArgValue::new("zsh"),
69+
Shell::Bash => PossibleValue::new("bash"),
70+
Shell::Elvish => PossibleValue::new("elvish"),
71+
Shell::Fish => PossibleValue::new("fish"),
72+
Shell::PowerShell => PossibleValue::new("powershell"),
73+
Shell::Zsh => PossibleValue::new("zsh"),
7474
})
7575
}
7676
}

src/build/arg/mod.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
mod arg_value;
21
#[cfg(debug_assertions)]
32
pub mod debug_asserts;
3+
mod possible_value;
44
mod settings;
55
#[cfg(test)]
66
mod tests;
77
mod value_hint;
88

9-
pub use self::arg_value::ArgValue;
9+
pub use self::possible_value::PossibleValue;
1010
pub use self::settings::{ArgFlags, ArgSettings};
1111
pub use self::value_hint::ValueHint;
1212

@@ -102,7 +102,7 @@ pub struct Arg<'help> {
102102
pub(crate) short_aliases: Vec<(char, bool)>, // (name, visible)
103103
pub(crate) disp_ord: usize,
104104
pub(crate) unified_ord: usize,
105-
pub(crate) possible_vals: Vec<ArgValue<'help>>,
105+
pub(crate) possible_vals: Vec<PossibleValue<'help>>,
106106
pub(crate) val_names: Vec<&'help str>,
107107
pub(crate) num_vals: Option<usize>,
108108
pub(crate) max_occurs: Option<usize>,
@@ -231,7 +231,7 @@ impl<'help> Arg<'help> {
231231

232232
/// Get the list of the possible values for this argument, if any
233233
#[inline]
234-
pub fn get_possible_values(&self) -> Option<&[ArgValue]> {
234+
pub fn get_possible_values(&self) -> Option<&[PossibleValue]> {
235235
if self.possible_vals.is_empty() {
236236
None
237237
} else {
@@ -1959,7 +1959,7 @@ impl<'help> Arg<'help> {
19591959
///
19601960
/// **NOTE:** This setting only applies to [options] and [positional arguments]
19611961
///
1962-
/// **NOTE:** You can use both strings directly or use [`ArgValue`] if you want more control
1962+
/// **NOTE:** You can use both strings directly or use [`PossibleValue`] if you want more control
19631963
/// over single possible values.
19641964
///
19651965
/// # Examples
@@ -1971,16 +1971,16 @@ impl<'help> Arg<'help> {
19711971
/// .possible_values(["fast", "slow", "medium"])
19721972
/// # ;
19731973
/// ```
1974-
/// The same using [`ArgValue`]:
1974+
/// The same using [`PossibleValue`]:
19751975
///
19761976
/// ```rust
1977-
/// # use clap::{App, Arg, ArgValue};
1977+
/// # use clap::{App, Arg, PossibleValue};
19781978
/// Arg::new("mode").takes_value(true).possible_values([
1979-
/// ArgValue::new("fast"),
1979+
/// PossibleValue::new("fast"),
19801980
/// // value with a help text
1981-
/// ArgValue::new("slow").about("not that fast"),
1981+
/// PossibleValue::new("slow").about("not that fast"),
19821982
/// // value that is hidden from completion and help text
1983-
/// ArgValue::new("medium").hidden(true),
1983+
/// PossibleValue::new("medium").hidden(true),
19841984
/// ])
19851985
/// # ;
19861986
/// ```
@@ -2020,7 +2020,7 @@ impl<'help> Arg<'help> {
20202020
pub fn possible_values<I, T>(mut self, values: I) -> Self
20212021
where
20222022
I: IntoIterator<Item = T>,
2023-
T: Into<ArgValue<'help>>,
2023+
T: Into<PossibleValue<'help>>,
20242024
{
20252025
self.possible_vals
20262026
.extend(values.into_iter().map(|value| value.into()));
@@ -2032,7 +2032,7 @@ impl<'help> Arg<'help> {
20322032
///
20332033
/// **NOTE:** This setting only applies to [options] and [positional arguments]
20342034
///
2035-
/// **NOTE:** You can use both strings directly or use [`ArgValue`] if you want more controll
2035+
/// **NOTE:** You can use both strings directly or use [`PossibleValue`] if you want more controll
20362036
/// over single possible values.
20372037
///
20382038
/// # Examples
@@ -2046,16 +2046,16 @@ impl<'help> Arg<'help> {
20462046
/// .possible_value("medium")
20472047
/// # ;
20482048
/// ```
2049-
/// The same using [`ArgValue`]:
2049+
/// The same using [`PossibleValue`]:
20502050
///
20512051
/// ```rust
2052-
/// # use clap::{App, Arg, ArgValue};
2052+
/// # use clap::{App, Arg, PossibleValue};
20532053
/// Arg::new("mode").takes_value(true)
2054-
/// .possible_value(ArgValue::new("fast"))
2054+
/// .possible_value(PossibleValue::new("fast"))
20552055
/// // value with a help text
2056-
/// .possible_value(ArgValue::new("slow").about("not that fast"))
2056+
/// .possible_value(PossibleValue::new("slow").about("not that fast"))
20572057
/// // value that is hidden from completion and help text
2058-
/// .possible_value(ArgValue::new("medium").hidden(true))
2058+
/// .possible_value(PossibleValue::new("medium").hidden(true))
20592059
/// # ;
20602060
/// ```
20612061
///
@@ -2097,7 +2097,7 @@ impl<'help> Arg<'help> {
20972097
/// [positional arguments]: Arg::index()
20982098
pub fn possible_value<T>(mut self, value: T) -> Self
20992099
where
2100-
T: Into<ArgValue<'help>>,
2100+
T: Into<PossibleValue<'help>>,
21012101
{
21022102
self.possible_vals.push(value.into());
21032103
self.takes_value(true)

0 commit comments

Comments
 (0)