Skip to content

Commit

Permalink
Merge pull request #3753 from epage/deprecate
Browse files Browse the repository at this point in the history
fix: Deprecate value_parser predecesor
  • Loading branch information
epage committed May 25, 2022
2 parents a9b3acf + 408ca3c commit 999647f
Show file tree
Hide file tree
Showing 99 changed files with 1,930 additions and 1,470 deletions.
8 changes: 4 additions & 4 deletions benches/03_complex.rs
Expand Up @@ -24,9 +24,9 @@ macro_rules! create_app {
arg!([positional2] "tests positionals with exclusions"),
arg!(-O --Option <option3> "tests options with specific value sets")
.required(false)
.possible_values(OPT3_VALS),
.value_parser(OPT3_VALS),
arg!([positional3] ... "tests positionals with specific values")
.possible_values(POS3_VALS),
.value_parser(POS3_VALS),
arg!(--multvals "Tests multiple values not mult occs").required(false).value_names(&["one", "two"]),
arg!(
--multvalsmo "Tests multiple values, not mult occs"
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn build_from_builder(c: &mut Criterion) {
.long("Option")
.takes_value(true)
.help("tests options with specific value sets")
.possible_values(OPT3_VALS),
.value_parser(OPT3_VALS),
)
.arg(
Arg::new("positional3")
Expand All @@ -105,7 +105,7 @@ pub fn build_from_builder(c: &mut Criterion) {
.multiple_occurrences(true)
.help("tests positionals with specific values")
.index(4)
.possible_values(POS3_VALS),
.value_parser(POS3_VALS),
)
.arg(
Arg::new("multvals")
Expand Down
22 changes: 8 additions & 14 deletions benches/05_ripgrep.rs
Expand Up @@ -3,7 +3,7 @@
//
// CLI used is adapted from ripgrep 48a8a3a691220f9e5b2b08f4051abe8655ea7e8a

use clap::{Arg, Command};
use clap::{value_parser, Arg, Command};
use criterion::{criterion_group, criterion_main, Criterion};
use std::collections::HashMap;
use std::io::Cursor;
Expand Down Expand Up @@ -352,7 +352,7 @@ where
.value_name("WHEN")
.takes_value(true)
.hide_possible_values(true)
.possible_values(["never", "auto", "always", "ansi"]),
.value_parser(["never", "auto", "always", "ansi"]),
)
.arg(
flag("colors")
Expand Down Expand Up @@ -394,19 +394,19 @@ where
flag("after-context")
.short('A')
.value_name("NUM")
.validator(validate_number),
.value_parser(value_parser!(usize)),
)
.arg(
flag("before-context")
.short('B')
.value_name("NUM")
.validator(validate_number),
.value_parser(value_parser!(usize)),
)
.arg(
flag("context")
.short('C')
.value_name("NUM")
.validator(validate_number),
.value_parser(value_parser!(usize)),
)
.arg(flag("column"))
.arg(flag("context-separator").value_name("SEPARATOR"))
Expand Down Expand Up @@ -434,12 +434,12 @@ where
flag("max-count")
.short('m')
.value_name("NUM")
.validator(validate_number),
.value_parser(value_parser!(usize)),
)
.arg(
flag("maxdepth")
.value_name("NUM")
.validator(validate_number),
.value_parser(value_parser!(usize)),
)
.arg(flag("mmap"))
.arg(flag("no-messages"))
Expand All @@ -458,7 +458,7 @@ where
flag("threads")
.short('j')
.value_name("ARG")
.validator(validate_number),
.value_parser(value_parser!(usize)),
)
.arg(flag("vimgrep"))
.arg(
Expand Down Expand Up @@ -933,12 +933,6 @@ lazy_static! {
};
}

fn validate_number(s: &str) -> Result<(), String> {
s.parse::<usize>()
.map(|_| ())
.map_err(|err| err.to_string())
}

criterion_group!(
benches,
build_rg_with_short_help,
Expand Down
28 changes: 14 additions & 14 deletions clap_complete/examples/completion-derive.rs
Expand Up @@ -26,34 +26,34 @@ use std::path::PathBuf;
)]
struct Opt {
/// If provided, outputs the completion file for given shell
#[clap(long = "generate", arg_enum)]
#[clap(long = "generate", arg_enum, value_parser)]
generator: Option<Shell>,
// Showcasing all possible ValueHints:
#[clap(long, value_hint = ValueHint::Unknown)]
#[clap(long, value_hint = ValueHint::Unknown, value_parser)]
unknown: Option<String>,
#[clap(long, value_hint = ValueHint::Other)]
#[clap(long, value_hint = ValueHint::Other, value_parser)]
other: Option<String>,
#[clap(short, long, value_hint = ValueHint::AnyPath)]
#[clap(short, long, value_hint = ValueHint::AnyPath, value_parser)]
path: Option<PathBuf>,
#[clap(short, long, value_hint = ValueHint::FilePath)]
#[clap(short, long, value_hint = ValueHint::FilePath, value_parser)]
file: Option<PathBuf>,
#[clap(short, long, value_hint = ValueHint::DirPath)]
#[clap(short, long, value_hint = ValueHint::DirPath, value_parser)]
dir: Option<PathBuf>,
#[clap(short, long, value_hint = ValueHint::ExecutablePath)]
#[clap(short, long, value_hint = ValueHint::ExecutablePath, value_parser)]
exe: Option<PathBuf>,
#[clap(long, parse(from_os_str), value_hint = ValueHint::CommandName)]
#[clap(long, value_hint = ValueHint::CommandName, value_parser)]
cmd_name: Option<OsString>,
#[clap(short, long, value_hint = ValueHint::CommandString)]
#[clap(short, long, value_hint = ValueHint::CommandString, value_parser)]
cmd: Option<String>,
#[clap(value_hint = ValueHint::CommandWithArguments)]
#[clap(value_hint = ValueHint::CommandWithArguments, value_parser)]
command_with_args: Vec<String>,
#[clap(short, long, value_hint = ValueHint::Username)]
#[clap(short, long, value_hint = ValueHint::Username, value_parser)]
user: Option<String>,
#[clap(short, long, value_hint = ValueHint::Hostname)]
#[clap(short, long, value_hint = ValueHint::Hostname, value_parser)]
host: Option<String>,
#[clap(long, value_hint = ValueHint::Url)]
#[clap(long, value_hint = ValueHint::Url, value_parser)]
url: Option<String>,
#[clap(long, value_hint = ValueHint::EmailAddress)]
#[clap(long, value_hint = ValueHint::EmailAddress, value_parser)]
email: Option<String>,
}

Expand Down
8 changes: 4 additions & 4 deletions clap_complete/examples/completion.rs
Expand Up @@ -12,7 +12,7 @@
//! . ./value_hints.fish
//! ./target/debug/examples/value_hints --<TAB>
//! ```
use clap::{Arg, Command, ValueHint};
use clap::{value_parser, Arg, Command, ValueHint};
use clap_complete::{generate, Generator, Shell};
use std::io;

Expand All @@ -23,7 +23,7 @@ fn build_cli() -> Command<'static> {
.arg(
Arg::new("generator")
.long("generate")
.possible_values(Shell::possible_values()),
.value_parser(value_parser!(Shell)),
)
.arg(
Arg::new("unknown")
Expand Down Expand Up @@ -99,9 +99,9 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
fn main() {
let matches = build_cli().get_matches();

if let Ok(generator) = matches.value_of_t::<Shell>("generator") {
if let Some(generator) = matches.get_one::<Shell>("generator") {
let mut cmd = build_cli();
eprintln!("Generating completion file for {}...", generator);
print_completions(generator, &mut cmd);
print_completions(*generator, &mut cmd);
}
}
2 changes: 1 addition & 1 deletion clap_complete/examples/dynamic.rs
Expand Up @@ -13,7 +13,7 @@ fn command() -> clap::Command<'static> {
clap::Arg::new("format")
.long("--format")
.short('F')
.possible_values(["json", "yaml", "toml"]),
.value_parser(["json", "yaml", "toml"]),
)
.args_conflicts_with_subcommands(true);
let cmd = clap_complete::dynamic::bash::CompleteCommand::augment_subcommands(cmd);
Expand Down
1 change: 1 addition & 0 deletions clap_complete/src/generator/utils.rs
Expand Up @@ -128,6 +128,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::PossibleValue<'help>>> {
#![allow(deprecated)]
if !a.is_takes_value_set() {
None
} else if let Some(pvs) = a.get_possible_values() {
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/src/lib.rs
Expand Up @@ -22,7 +22,7 @@
//! ## Example
//!
//! ```rust,no_run
//! use clap::{Command, AppSettings, Arg, ValueHint};
//! use clap::{Command, AppSettings, Arg, ValueHint, value_parser};
//! use clap_complete::{generate, Generator, Shell};
//! use std::io;
//!
Expand All @@ -35,7 +35,7 @@
//! .arg(
//! Arg::new("generator")
//! .long("generate")
//! .possible_values(Shell::possible_values()),
//! .value_parser(value_parser!(Shell)),
//! )
//! }
//!
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/shells/bash.rs
Expand Up @@ -201,7 +201,7 @@ fn all_options_for_path(cmd: &Command, path: &str) -> String {
write!(&mut opts, "--{} ", long).unwrap();
}
for pos in p.get_positionals() {
if let Some(vals) = pos.get_possible_values() {
if let Some(vals) = utils::possible_values(pos) {
for value in vals {
write!(&mut opts, "{} ", value.get_name()).unwrap();
}
Expand Down
3 changes: 2 additions & 1 deletion clap_complete/src/shells/shell.rs
Expand Up @@ -23,7 +23,8 @@ pub enum Shell {
}

impl Shell {
/// Report all `possible_values`
/// Deprecated, replaced with [`ArgEnumValueParser`][clap::builder::ArgEnumValueParser]
#[deprecated(since = "3.2.0", note = "Replaced with `ArgEnumValueParser`")]
pub fn possible_values() -> impl Iterator<Item = PossibleValue<'static>> {
Shell::value_variants()
.iter()
Expand Down
7 changes: 4 additions & 3 deletions clap_complete/tests/common.rs
Expand Up @@ -30,7 +30,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> {
.long("config")
.visible_alias("conf"),
)
.arg(clap::Arg::new("choice").possible_values(["first", "second"]))
.arg(clap::Arg::new("choice").value_parser(["first", "second"]))
.subcommand(
clap::Command::new("test").about("tests things").arg(
clap::Arg::new("case")
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> {
clap::Arg::new("config")
.long("config")
.takes_value(true)
.possible_values([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.help("the other case to test"),
),
),
Expand All @@ -154,7 +154,8 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> {
.arg(
clap::Arg::new("choice")
.long("choice")
.possible_values(["bash", "fish", "zsh"]),
.takes_value(true)
.value_parser(["bash", "fish", "zsh"]),
)
.arg(
clap::Arg::new("unknown")
Expand Down
7 changes: 4 additions & 3 deletions clap_complete_fig/tests/common.rs
Expand Up @@ -30,7 +30,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> {
.long("config")
.visible_alias("conf"),
)
.arg(clap::Arg::new("choice").possible_values(["first", "second"]))
.arg(clap::Arg::new("choice").value_parser(["first", "second"]))
.subcommand(
clap::Command::new("test").about("tests things").arg(
clap::Arg::new("case")
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> {
clap::Arg::new("config")
.long("config")
.takes_value(true)
.possible_values([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.help("the other case to test"),
),
),
Expand All @@ -154,7 +154,8 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> {
.arg(
clap::Arg::new("choice")
.long("choice")
.possible_values(["bash", "fish", "zsh"]),
.takes_value(true)
.value_parser(["bash", "fish", "zsh"]),
)
.arg(
clap::Arg::new("unknown")
Expand Down
7 changes: 4 additions & 3 deletions clap_mangen/tests/common.rs
Expand Up @@ -27,7 +27,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> {
.long("config")
.visible_alias("conf"),
)
.arg(clap::Arg::new("choice").possible_values(["first", "second"]))
.arg(clap::Arg::new("choice").value_parser(["first", "second"]))
.subcommand(
clap::Command::new("test").about("tests things").arg(
clap::Arg::new("case")
Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> {
clap::Arg::new("config")
.long("config")
.takes_value(true)
.possible_values([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.help("the other case to test"),
),
),
Expand All @@ -143,7 +143,8 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> {
.arg(
clap::Arg::new("choice")
.long("choice")
.possible_values(["bash", "fish", "zsh"]),
.takes_value(true)
.value_parser(["bash", "fish", "zsh"]),
)
.arg(
clap::Arg::new("unknown")
Expand Down
4 changes: 2 additions & 2 deletions examples/derive_ref/custom-bool.md
Expand Up @@ -31,14 +31,14 @@ USAGE:
For more information try --help

$ custom-bool --foo true false
[examples/derive_ref/custom-bool.rs:31] opt = Opt {
[examples/derive_ref/custom-bool.rs:32] opt = Opt {
foo: true,
bar: false,
boom: false,
}

$ custom-bool --foo true --bar true false
[examples/derive_ref/custom-bool.rs:31] opt = Opt {
[examples/derive_ref/custom-bool.rs:32] opt = Opt {
foo: true,
bar: true,
boom: false,
Expand Down
1 change: 1 addition & 0 deletions examples/derive_ref/custom-bool.rs
@@ -1,3 +1,4 @@
#![allow(deprecated)] // Can't opt-out of implicit flags until #3405
use clap::Parser;

#[derive(Parser, Debug, PartialEq)]
Expand Down

0 comments on commit 999647f

Please sign in to comment.