Skip to content

Commit

Permalink
fix(derive)!: Remove value_parser/action defaulted attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 23, 2022
1 parent f47c361 commit 29cfe2d
Show file tree
Hide file tree
Showing 27 changed files with 71 additions and 77 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## 5.0.0 - Upcoming

### Breaking Changes

- *(derive)* Removed `#[clap(value_parser)]` and `#[clap(action)]` defaulted attributes (its the default) (#3976)

## 4.0.0 - Upcoming

### Breaking Changes
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, value_parser)]
#[clap(long = "generate", arg_enum)]
generator: Option<Shell>,
// Showcasing all possible ValueHints:
#[clap(long, value_hint = ValueHint::Unknown, value_parser)]
#[clap(long, value_hint = ValueHint::Unknown)]
unknown: Option<String>,
#[clap(long, value_hint = ValueHint::Other, value_parser)]
#[clap(long, value_hint = ValueHint::Other)]
other: Option<String>,
#[clap(short, long, value_hint = ValueHint::AnyPath, value_parser)]
#[clap(short, long, value_hint = ValueHint::AnyPath)]
path: Option<PathBuf>,
#[clap(short, long, value_hint = ValueHint::FilePath, value_parser)]
#[clap(short, long, value_hint = ValueHint::FilePath)]
file: Option<PathBuf>,
#[clap(short, long, value_hint = ValueHint::DirPath, value_parser)]
#[clap(short, long, value_hint = ValueHint::DirPath)]
dir: Option<PathBuf>,
#[clap(short, long, value_hint = ValueHint::ExecutablePath, value_parser)]
#[clap(short, long, value_hint = ValueHint::ExecutablePath)]
exe: Option<PathBuf>,
#[clap(long, value_hint = ValueHint::CommandName, value_parser)]
#[clap(long, value_hint = ValueHint::CommandName)]
cmd_name: Option<OsString>,
#[clap(short, long, value_hint = ValueHint::CommandString, value_parser)]
#[clap(short, long, value_hint = ValueHint::CommandString)]
cmd: Option<String>,
#[clap(value_hint = ValueHint::CommandWithArguments, value_parser)]
#[clap(value_hint = ValueHint::CommandWithArguments)]
command_with_args: Vec<String>,
#[clap(short, long, value_hint = ValueHint::Username, value_parser)]
#[clap(short, long, value_hint = ValueHint::Username)]
user: Option<String>,
#[clap(short, long, value_hint = ValueHint::Hostname, value_parser)]
#[clap(short, long, value_hint = ValueHint::Hostname)]
host: Option<String>,
#[clap(long, value_hint = ValueHint::Url, value_parser)]
#[clap(long, value_hint = ValueHint::Url)]
url: Option<String>,
#[clap(long, value_hint = ValueHint::EmailAddress, value_parser)]
#[clap(long, value_hint = ValueHint::EmailAddress)]
email: Option<String>,
}

Expand Down
2 changes: 2 additions & 0 deletions clap_derive/src/attrs.rs
Expand Up @@ -429,11 +429,13 @@ impl Attrs {
self.push_method(ident, self.name.clone().translate(*self.casing));
}

#[cfg(not(feature = "unstable-v5"))]
ValueParser(ident) => {
use crate::attrs::ValueParser;
self.value_parser = Some(ValueParser::Implicit(ident));
}

#[cfg(not(feature = "unstable-v5"))]
Action(ident) => {
use crate::attrs::Action;
self.action = Some(Action::Implicit(ident));
Expand Down
4 changes: 4 additions & 0 deletions clap_derive/src/parse.rs
Expand Up @@ -25,7 +25,9 @@ pub enum ClapAttr {
// single-identifier attributes
Short(Ident),
Long(Ident),
#[cfg(not(feature = "unstable-v5"))]
ValueParser(Ident),
#[cfg(not(feature = "unstable-v5"))]
Action(Ident),
Env(Ident),
Flatten(Ident),
Expand Down Expand Up @@ -143,7 +145,9 @@ impl Parse for ClapAttr {
match name_str.as_ref() {
"long" => Ok(Long(name)),
"short" => Ok(Short(name)),
#[cfg(not(feature = "unstable-v5"))]
"value_parser" => Ok(ValueParser(name)),
#[cfg(not(feature = "unstable-v5"))]
"action" => Ok(Action(name)),
"env" => Ok(Env(name)),
"flatten" => Ok(Flatten(name)),
Expand Down
2 changes: 1 addition & 1 deletion examples/cargo-example-derive.rs
Expand Up @@ -10,7 +10,7 @@ enum Cargo {
#[derive(clap::Args)]
#[clap(author, version, about, long_about = None)]
struct ExampleDerive {
#[clap(long, value_parser)]
#[clap(long)]
manifest_path: Option<std::path::PathBuf>,
}

Expand Down
4 changes: 2 additions & 2 deletions examples/demo.rs
Expand Up @@ -5,11 +5,11 @@ use clap::Parser;
#[clap(author, version, about, long_about = None)]
struct Args {
/// Name of the person to greet
#[clap(short, long, value_parser)]
#[clap(short, long)]
name: String,

/// Number of times to greet
#[clap(short, long, value_parser, default_value_t = 1)]
#[clap(short, long, default_value_t = 1)]
count: u8,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/derive_ref/augment_args.rs
Expand Up @@ -2,7 +2,7 @@ use clap::{arg, Args, Command, FromArgMatches as _};

#[derive(Args, Debug)]
struct DerivedArgs {
#[clap(short, long, action)]
#[clap(short, long)]
derived: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/derive_ref/augment_subcommands.rs
Expand Up @@ -3,7 +3,7 @@ use clap::{Command, FromArgMatches as _, Parser, Subcommand as _};
#[derive(Parser, Debug)]
enum Subcommands {
Derived {
#[clap(short, long, action)]
#[clap(short, long)]
derived_flag: bool,
},
}
Expand Down
2 changes: 1 addition & 1 deletion examples/derive_ref/flatten_hand_args.rs
Expand Up @@ -69,7 +69,7 @@ impl Args for CliArgs {

#[derive(Parser, Debug)]
struct Cli {
#[clap(short, long, action)]
#[clap(short, long)]
top_level: bool,
#[clap(flatten)]
more_args: CliArgs,
Expand Down
6 changes: 2 additions & 4 deletions examples/derive_ref/hand_subcommand.rs
Expand Up @@ -3,14 +3,12 @@ use clap::{ArgMatches, Args as _, Command, FromArgMatches, Parser, Subcommand};

#[derive(Parser, Debug)]
struct AddArgs {
#[clap(value_parser)]
name: Vec<String>,
}
#[derive(Parser, Debug)]
struct RemoveArgs {
#[clap(short, long, action)]
#[clap(short, long)]
force: bool,
#[clap(value_parser)]
name: Vec<String>,
}

Expand Down Expand Up @@ -69,7 +67,7 @@ impl Subcommand for CliSub {

#[derive(Parser, Debug)]
struct Cli {
#[clap(short, long, action)]
#[clap(short, long)]
top_level: bool,
#[clap(subcommand)]
subcommand: CliSub,
Expand Down
6 changes: 3 additions & 3 deletions examples/escaped-positional-derive.rs
Expand Up @@ -3,13 +3,13 @@ use clap::Parser;
#[derive(Parser)] // requires `derive` feature
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(short = 'f', action)]
#[clap(short = 'f')]
eff: bool,

#[clap(short = 'p', value_name = "PEAR", value_parser)]
#[clap(short = 'p', value_name = "PEAR")]
pea: Option<String>,

#[clap(last = true, value_parser)]
#[clap(last = true)]
slop: Vec<String>,
}

Expand Down
16 changes: 4 additions & 12 deletions examples/git-derive.rs
Expand Up @@ -18,21 +18,19 @@ enum Commands {
#[clap(arg_required_else_help = true)]
Clone {
/// The remote to clone
#[clap(value_parser)]
remote: String,
},
/// pushes things
#[clap(arg_required_else_help = true)]
Push {
/// The remote to target
#[clap(value_parser)]
remote: String,
},
/// adds things
#[clap(arg_required_else_help = true)]
Add {
/// Stuff to add
#[clap(required = true, value_parser)]
#[clap(required = true)]
path: Vec<PathBuf>,
},
Stash(Stash),
Expand All @@ -53,19 +51,13 @@ struct Stash {
#[derive(Debug, Subcommand)]
enum StashCommands {
Push(StashPush),
Pop {
#[clap(value_parser)]
stash: Option<String>,
},
Apply {
#[clap(value_parser)]
stash: Option<String>,
},
Pop { stash: Option<String> },
Apply { stash: Option<String> },
}

#[derive(Debug, Args)]
struct StashPush {
#[clap(short, long, value_parser)]
#[clap(short, long)]
message: Option<String>,
}

Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial_derive/01_quick.rs
Expand Up @@ -6,11 +6,10 @@ use clap::{Parser, Subcommand};
#[clap(author, version, about, long_about = None)]
struct Cli {
/// Optional name to operate on
#[clap(value_parser)]
name: Option<String>,

/// Sets a custom config file
#[clap(short, long, value_parser, value_name = "FILE")]
#[clap(short, long, value_name = "FILE")]
config: Option<PathBuf>,

/// Turn debugging information on
Expand All @@ -26,7 +25,7 @@ enum Commands {
/// does testing things
Test {
/// lists test values
#[clap(short, long, action)]
#[clap(short, long)]
list: bool,
},
}
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_derive/02_app_settings.rs
Expand Up @@ -4,9 +4,9 @@ use clap::Parser;
#[clap(author, version, about, long_about = None)]
#[clap(allow_negative_numbers = true)]
struct Cli {
#[clap(long, value_parser)]
#[clap(long)]
two: String,
#[clap(long, value_parser)]
#[clap(long)]
one: String,
}

Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_derive/02_apps.rs
Expand Up @@ -6,9 +6,9 @@ use clap::Parser;
#[clap(version = "1.0")]
#[clap(about = "Does awesome things", long_about = None)]
struct Cli {
#[clap(long, value_parser)]
#[clap(long)]
two: String,
#[clap(long, value_parser)]
#[clap(long)]
one: String,
}

Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_derive/02_crate.rs
Expand Up @@ -3,9 +3,9 @@ use clap::Parser;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)] // Read from `Cargo.toml`
struct Cli {
#[clap(long, value_parser)]
#[clap(long)]
two: String,
#[clap(long, value_parser)]
#[clap(long)]
one: String,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/03_01_flag_bool.rs
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(short, long, action)]
#[clap(short, long)]
verbose: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/03_02_option.rs
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(short, long, value_parser)]
#[clap(short, long)]
name: Option<String>,
}

Expand Down
1 change: 0 additions & 1 deletion examples/tutorial_derive/03_03_positional.rs
Expand Up @@ -3,7 +3,6 @@ use clap::Parser;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(value_parser)]
name: Option<String>,
}

Expand Down
5 changes: 1 addition & 4 deletions examples/tutorial_derive/03_04_subcommands.rs
Expand Up @@ -11,10 +11,7 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Adds files to myapp
Add {
#[clap(value_parser)]
name: Option<String>,
},
Add { name: Option<String> },
}

fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/tutorial_derive/03_04_subcommands_alt.rs
Expand Up @@ -16,7 +16,6 @@ enum Commands {

#[derive(Args)]
struct Add {
#[clap(value_parser)]
name: Option<String>,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/03_05_default_values.rs
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(default_value_t = String::from("alice"), value_parser)]
#[clap(default_value_t = String::from("alice"))]
name: String,
}

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/04_01_enum.rs
Expand Up @@ -4,7 +4,7 @@ use clap::{ArgEnum, Parser};
#[clap(author, version, about, long_about = None)]
struct Cli {
/// What mode to run the program in
#[clap(arg_enum, value_parser)]
#[clap(arg_enum)]
mode: Mode,
}

Expand Down
14 changes: 7 additions & 7 deletions examples/tutorial_derive/04_03_relations.rs
Expand Up @@ -9,30 +9,30 @@ use clap::{ArgGroup, Parser};
))]
struct Cli {
/// set version manually
#[clap(long, value_name = "VER", value_parser)]
#[clap(long, value_name = "VER")]
set_ver: Option<String>,

/// auto inc major
#[clap(long, action)]
#[clap(long)]
major: bool,

/// auto inc minor
#[clap(long, action)]
#[clap(long)]
minor: bool,

/// auto inc patch
#[clap(long, action)]
#[clap(long)]
patch: bool,

/// some regular input
#[clap(group = "input", value_parser)]
#[clap(group = "input")]
input_file: Option<String>,

/// some special input argument
#[clap(long, group = "input", value_parser)]
#[clap(long, group = "input")]
spec_in: Option<String>,

#[clap(short, requires = "input", value_parser)]
#[clap(short, requires = "input")]
config: Option<String>,
}

Expand Down

0 comments on commit 29cfe2d

Please sign in to comment.