mirror of
https://github.com/clap-rs/clap
synced 2024-12-12 13:52:34 +00:00
fix(derive)!: Remove value_parser/action defaulted attributes
This commit is contained in:
parent
f47c361cdb
commit
6ecb7310a8
40 changed files with 107 additions and 134 deletions
|
@ -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/).
|
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
|
## 4.0.0 - Upcoming
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
|
|
@ -26,34 +26,34 @@ use std::path::PathBuf;
|
||||||
)]
|
)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
/// If provided, outputs the completion file for given shell
|
/// If provided, outputs the completion file for given shell
|
||||||
#[clap(long = "generate", arg_enum, value_parser)]
|
#[clap(long = "generate", arg_enum)]
|
||||||
generator: Option<Shell>,
|
generator: Option<Shell>,
|
||||||
// Showcasing all possible ValueHints:
|
// Showcasing all possible ValueHints:
|
||||||
#[clap(long, value_hint = ValueHint::Unknown, value_parser)]
|
#[clap(long, value_hint = ValueHint::Unknown)]
|
||||||
unknown: Option<String>,
|
unknown: Option<String>,
|
||||||
#[clap(long, value_hint = ValueHint::Other, value_parser)]
|
#[clap(long, value_hint = ValueHint::Other)]
|
||||||
other: Option<String>,
|
other: Option<String>,
|
||||||
#[clap(short, long, value_hint = ValueHint::AnyPath, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::AnyPath)]
|
||||||
path: Option<PathBuf>,
|
path: Option<PathBuf>,
|
||||||
#[clap(short, long, value_hint = ValueHint::FilePath, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::FilePath)]
|
||||||
file: Option<PathBuf>,
|
file: Option<PathBuf>,
|
||||||
#[clap(short, long, value_hint = ValueHint::DirPath, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::DirPath)]
|
||||||
dir: Option<PathBuf>,
|
dir: Option<PathBuf>,
|
||||||
#[clap(short, long, value_hint = ValueHint::ExecutablePath, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::ExecutablePath)]
|
||||||
exe: Option<PathBuf>,
|
exe: Option<PathBuf>,
|
||||||
#[clap(long, value_hint = ValueHint::CommandName, value_parser)]
|
#[clap(long, value_hint = ValueHint::CommandName)]
|
||||||
cmd_name: Option<OsString>,
|
cmd_name: Option<OsString>,
|
||||||
#[clap(short, long, value_hint = ValueHint::CommandString, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::CommandString)]
|
||||||
cmd: Option<String>,
|
cmd: Option<String>,
|
||||||
#[clap(value_hint = ValueHint::CommandWithArguments, value_parser)]
|
#[clap(value_hint = ValueHint::CommandWithArguments)]
|
||||||
command_with_args: Vec<String>,
|
command_with_args: Vec<String>,
|
||||||
#[clap(short, long, value_hint = ValueHint::Username, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::Username)]
|
||||||
user: Option<String>,
|
user: Option<String>,
|
||||||
#[clap(short, long, value_hint = ValueHint::Hostname, value_parser)]
|
#[clap(short, long, value_hint = ValueHint::Hostname)]
|
||||||
host: Option<String>,
|
host: Option<String>,
|
||||||
#[clap(long, value_hint = ValueHint::Url, value_parser)]
|
#[clap(long, value_hint = ValueHint::Url)]
|
||||||
url: Option<String>,
|
url: Option<String>,
|
||||||
#[clap(long, value_hint = ValueHint::EmailAddress, value_parser)]
|
#[clap(long, value_hint = ValueHint::EmailAddress)]
|
||||||
email: Option<String>,
|
email: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub mod bash {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct CompleteArgs {
|
pub struct CompleteArgs {
|
||||||
/// Path to write completion-registration to
|
/// Path to write completion-registration to
|
||||||
#[clap(long, required = true, value_parser)]
|
#[clap(long, required = true)]
|
||||||
register: Option<std::path::PathBuf>,
|
register: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
|
@ -30,36 +30,33 @@ pub mod bash {
|
||||||
required = true,
|
required = true,
|
||||||
value_name = "COMP_CWORD",
|
value_name = "COMP_CWORD",
|
||||||
hide_short_help = true,
|
hide_short_help = true,
|
||||||
group = "complete",
|
group = "complete"
|
||||||
value_parser
|
|
||||||
)]
|
)]
|
||||||
index: Option<usize>,
|
index: Option<usize>,
|
||||||
|
|
||||||
#[clap(long, hide_short_help = true, group = "complete", value_parser)]
|
#[clap(long, hide_short_help = true, group = "complete")]
|
||||||
ifs: Option<String>,
|
ifs: Option<String>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long = "type",
|
long = "type",
|
||||||
required = true,
|
required = true,
|
||||||
hide_short_help = true,
|
hide_short_help = true,
|
||||||
group = "complete",
|
group = "complete"
|
||||||
value_parser
|
|
||||||
)]
|
)]
|
||||||
comp_type: Option<CompType>,
|
comp_type: Option<CompType>,
|
||||||
|
|
||||||
#[clap(long, hide_short_help = true, group = "complete", action)]
|
#[clap(long, hide_short_help = true, group = "complete")]
|
||||||
space: bool,
|
space: bool,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
conflicts_with = "space",
|
conflicts_with = "space",
|
||||||
hide_short_help = true,
|
hide_short_help = true,
|
||||||
group = "complete",
|
group = "complete"
|
||||||
action
|
|
||||||
)]
|
)]
|
||||||
no_space: bool,
|
no_space: bool,
|
||||||
|
|
||||||
#[clap(raw = true, hide_short_help = true, group = "complete", value_parser)]
|
#[clap(raw = true, hide_short_help = true, group = "complete")]
|
||||||
comp_words: Vec<OsString>,
|
comp_words: Vec<OsString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -429,11 +429,13 @@ impl Attrs {
|
||||||
self.push_method(ident, self.name.clone().translate(*self.casing));
|
self.push_method(ident, self.name.clone().translate(*self.casing));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "unstable-v5"))]
|
||||||
ValueParser(ident) => {
|
ValueParser(ident) => {
|
||||||
use crate::attrs::ValueParser;
|
use crate::attrs::ValueParser;
|
||||||
self.value_parser = Some(ValueParser::Implicit(ident));
|
self.value_parser = Some(ValueParser::Implicit(ident));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "unstable-v5"))]
|
||||||
Action(ident) => {
|
Action(ident) => {
|
||||||
use crate::attrs::Action;
|
use crate::attrs::Action;
|
||||||
self.action = Some(Action::Implicit(ident));
|
self.action = Some(Action::Implicit(ident));
|
||||||
|
|
|
@ -25,7 +25,9 @@ pub enum ClapAttr {
|
||||||
// single-identifier attributes
|
// single-identifier attributes
|
||||||
Short(Ident),
|
Short(Ident),
|
||||||
Long(Ident),
|
Long(Ident),
|
||||||
|
#[cfg(not(feature = "unstable-v5"))]
|
||||||
ValueParser(Ident),
|
ValueParser(Ident),
|
||||||
|
#[cfg(not(feature = "unstable-v5"))]
|
||||||
Action(Ident),
|
Action(Ident),
|
||||||
Env(Ident),
|
Env(Ident),
|
||||||
Flatten(Ident),
|
Flatten(Ident),
|
||||||
|
@ -143,7 +145,9 @@ impl Parse for ClapAttr {
|
||||||
match name_str.as_ref() {
|
match name_str.as_ref() {
|
||||||
"long" => Ok(Long(name)),
|
"long" => Ok(Long(name)),
|
||||||
"short" => Ok(Short(name)),
|
"short" => Ok(Short(name)),
|
||||||
|
#[cfg(not(feature = "unstable-v5"))]
|
||||||
"value_parser" => Ok(ValueParser(name)),
|
"value_parser" => Ok(ValueParser(name)),
|
||||||
|
#[cfg(not(feature = "unstable-v5"))]
|
||||||
"action" => Ok(Action(name)),
|
"action" => Ok(Action(name)),
|
||||||
"env" => Ok(Env(name)),
|
"env" => Ok(Env(name)),
|
||||||
"flatten" => Ok(Flatten(name)),
|
"flatten" => Ok(Flatten(name)),
|
||||||
|
|
|
@ -10,7 +10,7 @@ enum Cargo {
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct ExampleDerive {
|
struct ExampleDerive {
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
manifest_path: Option<std::path::PathBuf>,
|
manifest_path: Option<std::path::PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ use clap::Parser;
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Name of the person to greet
|
/// Name of the person to greet
|
||||||
#[clap(short, long, value_parser)]
|
#[clap(short, long)]
|
||||||
name: String,
|
name: String,
|
||||||
|
|
||||||
/// Number of times to greet
|
/// Number of times to greet
|
||||||
#[clap(short, long, value_parser, default_value_t = 1)]
|
#[clap(short, long, default_value_t = 1)]
|
||||||
count: u8,
|
count: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use clap::{arg, Args, Command, FromArgMatches as _};
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
struct DerivedArgs {
|
struct DerivedArgs {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
derived: bool,
|
derived: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use clap::{Command, FromArgMatches as _, Parser, Subcommand as _};
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
enum Subcommands {
|
enum Subcommands {
|
||||||
Derived {
|
Derived {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
derived_flag: bool,
|
derived_flag: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl Args for CliArgs {
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
top_level: bool,
|
top_level: bool,
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
more_args: CliArgs,
|
more_args: CliArgs,
|
||||||
|
|
|
@ -3,14 +3,12 @@ use clap::{ArgMatches, Args as _, Command, FromArgMatches, Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct AddArgs {
|
struct AddArgs {
|
||||||
#[clap(value_parser)]
|
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
}
|
}
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct RemoveArgs {
|
struct RemoveArgs {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
force: bool,
|
force: bool,
|
||||||
#[clap(value_parser)]
|
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +67,7 @@ impl Subcommand for CliSub {
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
top_level: bool,
|
top_level: bool,
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
subcommand: CliSub,
|
subcommand: CliSub,
|
||||||
|
|
|
@ -3,13 +3,13 @@ use clap::Parser;
|
||||||
#[derive(Parser)] // requires `derive` feature
|
#[derive(Parser)] // requires `derive` feature
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(short = 'f', action)]
|
#[clap(short = 'f')]
|
||||||
eff: bool,
|
eff: bool,
|
||||||
|
|
||||||
#[clap(short = 'p', value_name = "PEAR", value_parser)]
|
#[clap(short = 'p', value_name = "PEAR")]
|
||||||
pea: Option<String>,
|
pea: Option<String>,
|
||||||
|
|
||||||
#[clap(last = true, value_parser)]
|
#[clap(last = true)]
|
||||||
slop: Vec<String>,
|
slop: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,21 +18,19 @@ enum Commands {
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
Clone {
|
Clone {
|
||||||
/// The remote to clone
|
/// The remote to clone
|
||||||
#[clap(value_parser)]
|
|
||||||
remote: String,
|
remote: String,
|
||||||
},
|
},
|
||||||
/// pushes things
|
/// pushes things
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
Push {
|
Push {
|
||||||
/// The remote to target
|
/// The remote to target
|
||||||
#[clap(value_parser)]
|
|
||||||
remote: String,
|
remote: String,
|
||||||
},
|
},
|
||||||
/// adds things
|
/// adds things
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
Add {
|
Add {
|
||||||
/// Stuff to add
|
/// Stuff to add
|
||||||
#[clap(required = true, value_parser)]
|
#[clap(required = true)]
|
||||||
path: Vec<PathBuf>,
|
path: Vec<PathBuf>,
|
||||||
},
|
},
|
||||||
Stash(Stash),
|
Stash(Stash),
|
||||||
|
@ -53,19 +51,13 @@ struct Stash {
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
enum StashCommands {
|
enum StashCommands {
|
||||||
Push(StashPush),
|
Push(StashPush),
|
||||||
Pop {
|
Pop { stash: Option<String> },
|
||||||
#[clap(value_parser)]
|
Apply { stash: Option<String> },
|
||||||
stash: Option<String>,
|
|
||||||
},
|
|
||||||
Apply {
|
|
||||||
#[clap(value_parser)]
|
|
||||||
stash: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
struct StashPush {
|
struct StashPush {
|
||||||
#[clap(short, long, value_parser)]
|
#[clap(short, long)]
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,10 @@ use clap::{Parser, Subcommand};
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// Optional name to operate on
|
/// Optional name to operate on
|
||||||
#[clap(value_parser)]
|
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
/// Sets a custom config file
|
/// Sets a custom config file
|
||||||
#[clap(short, long, value_parser, value_name = "FILE")]
|
#[clap(short, long, value_name = "FILE")]
|
||||||
config: Option<PathBuf>,
|
config: Option<PathBuf>,
|
||||||
|
|
||||||
/// Turn debugging information on
|
/// Turn debugging information on
|
||||||
|
@ -26,7 +25,7 @@ enum Commands {
|
||||||
/// does testing things
|
/// does testing things
|
||||||
Test {
|
Test {
|
||||||
/// lists test values
|
/// lists test values
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
list: bool,
|
list: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ use clap::Parser;
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
#[clap(allow_negative_numbers = true)]
|
#[clap(allow_negative_numbers = true)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
two: String,
|
two: String,
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
one: String,
|
one: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ use clap::Parser;
|
||||||
#[clap(version = "1.0")]
|
#[clap(version = "1.0")]
|
||||||
#[clap(about = "Does awesome things", long_about = None)]
|
#[clap(about = "Does awesome things", long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
two: String,
|
two: String,
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
one: String,
|
one: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ use clap::Parser;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about = None)] // Read from `Cargo.toml`
|
#[clap(author, version, about, long_about = None)] // Read from `Cargo.toml`
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
two: String,
|
two: String,
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
one: String,
|
one: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use clap::Parser;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long)]
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use clap::Parser;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(short, long, value_parser)]
|
#[clap(short, long)]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ use clap::Parser;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(value_parser)]
|
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,7 @@ struct Cli {
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Adds files to myapp
|
/// Adds files to myapp
|
||||||
Add {
|
Add { name: Option<String> },
|
||||||
#[clap(value_parser)]
|
|
||||||
name: Option<String>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -16,7 +16,6 @@ enum Commands {
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
struct Add {
|
struct Add {
|
||||||
#[clap(value_parser)]
|
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use clap::Parser;
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(default_value_t = String::from("alice"), value_parser)]
|
#[clap(default_value_t = String::from("alice"))]
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use clap::{ArgEnum, Parser};
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// What mode to run the program in
|
/// What mode to run the program in
|
||||||
#[clap(arg_enum, value_parser)]
|
#[clap(arg_enum)]
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,30 +9,30 @@ use clap::{ArgGroup, Parser};
|
||||||
))]
|
))]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// set version manually
|
/// set version manually
|
||||||
#[clap(long, value_name = "VER", value_parser)]
|
#[clap(long, value_name = "VER")]
|
||||||
set_ver: Option<String>,
|
set_ver: Option<String>,
|
||||||
|
|
||||||
/// auto inc major
|
/// auto inc major
|
||||||
#[clap(long, action)]
|
#[clap(long)]
|
||||||
major: bool,
|
major: bool,
|
||||||
|
|
||||||
/// auto inc minor
|
/// auto inc minor
|
||||||
#[clap(long, action)]
|
#[clap(long)]
|
||||||
minor: bool,
|
minor: bool,
|
||||||
|
|
||||||
/// auto inc patch
|
/// auto inc patch
|
||||||
#[clap(long, action)]
|
#[clap(long)]
|
||||||
patch: bool,
|
patch: bool,
|
||||||
|
|
||||||
/// some regular input
|
/// some regular input
|
||||||
#[clap(group = "input", value_parser)]
|
#[clap(group = "input")]
|
||||||
input_file: Option<String>,
|
input_file: Option<String>,
|
||||||
|
|
||||||
/// some special input argument
|
/// some special input argument
|
||||||
#[clap(long, group = "input", value_parser)]
|
#[clap(long, group = "input")]
|
||||||
spec_in: Option<String>,
|
spec_in: Option<String>,
|
||||||
|
|
||||||
#[clap(short, requires = "input", value_parser)]
|
#[clap(short, requires = "input")]
|
||||||
config: Option<String>,
|
config: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,30 +4,29 @@ use clap::{CommandFactory, ErrorKind, Parser};
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// set version manually
|
/// set version manually
|
||||||
#[clap(long, value_name = "VER", value_parser)]
|
#[clap(long, value_name = "VER")]
|
||||||
set_ver: Option<String>,
|
set_ver: Option<String>,
|
||||||
|
|
||||||
/// auto inc major
|
/// auto inc major
|
||||||
#[clap(long, action)]
|
#[clap(long)]
|
||||||
major: bool,
|
major: bool,
|
||||||
|
|
||||||
/// auto inc minor
|
/// auto inc minor
|
||||||
#[clap(long, action)]
|
#[clap(long)]
|
||||||
minor: bool,
|
minor: bool,
|
||||||
|
|
||||||
/// auto inc patch
|
/// auto inc patch
|
||||||
#[clap(long, action)]
|
#[clap(long)]
|
||||||
patch: bool,
|
patch: bool,
|
||||||
|
|
||||||
/// some regular input
|
/// some regular input
|
||||||
#[clap(value_parser)]
|
|
||||||
input_file: Option<String>,
|
input_file: Option<String>,
|
||||||
|
|
||||||
/// some special input argument
|
/// some special input argument
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
spec_in: Option<String>,
|
spec_in: Option<String>,
|
||||||
|
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
config: Option<String>,
|
config: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ use clap::Parser;
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// Network port to use
|
/// Network port to use
|
||||||
#[clap(value_parser)]
|
|
||||||
port: u16,
|
port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,19 @@ use std::error::Error;
|
||||||
#[derive(Parser, Debug)] // requires `derive` feature
|
#[derive(Parser, Debug)] // requires `derive` feature
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Implicitly using `std::str::FromStr`
|
/// Implicitly using `std::str::FromStr`
|
||||||
#[clap(short = 'O', value_parser)]
|
#[clap(short = 'O')]
|
||||||
optimization: Option<usize>,
|
optimization: Option<usize>,
|
||||||
|
|
||||||
/// Allow invalid UTF-8 paths
|
/// Allow invalid UTF-8 paths
|
||||||
#[clap(short = 'I', value_parser, value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
|
#[clap(short = 'I', value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
|
||||||
include: Option<std::path::PathBuf>,
|
include: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
/// Handle IP addresses
|
/// Handle IP addresses
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
bind: Option<std::net::IpAddr>,
|
bind: Option<std::net::IpAddr>,
|
||||||
|
|
||||||
/// Allow human-readable durations
|
/// Allow human-readable durations
|
||||||
#[clap(long, value_parser)]
|
#[clap(long)]
|
||||||
sleep: Option<humantime::Duration>,
|
sleep: Option<humantime::Duration>,
|
||||||
|
|
||||||
/// Hand-written parser for tuples
|
/// Hand-written parser for tuples
|
||||||
|
|
|
@ -36,10 +36,10 @@ use std::ffi::OsString;
|
||||||
/// #[clap(name = "demo")]
|
/// #[clap(name = "demo")]
|
||||||
/// struct Context {
|
/// struct Context {
|
||||||
/// /// More verbose output
|
/// /// More verbose output
|
||||||
/// #[clap(long, value_parser)]
|
/// #[clap(long)]
|
||||||
/// verbose: bool,
|
/// verbose: bool,
|
||||||
/// /// An optional name
|
/// /// An optional name
|
||||||
/// #[clap(short, long, value_parser)]
|
/// #[clap(short, long)]
|
||||||
/// name: Option<String>,
|
/// name: Option<String>,
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -354,7 +354,7 @@ pub trait Subcommand: FromArgMatches + Sized {
|
||||||
#[cfg_attr(feature = "derive", doc = " ```")]
|
#[cfg_attr(feature = "derive", doc = " ```")]
|
||||||
/// #[derive(clap::Parser)]
|
/// #[derive(clap::Parser)]
|
||||||
/// struct Args {
|
/// struct Args {
|
||||||
/// #[clap(value_enum, value_parser)]
|
/// #[clap(value_enum)]
|
||||||
/// level: Level,
|
/// level: Level,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,7 +11,7 @@ use clap::Parser;
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "basic")]
|
#[clap(name = "basic")]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
#[clap(value_parser, default_value_t = -10)]
|
#[clap(default_value_t = -10)]
|
||||||
value: u32,
|
value: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
error[E0600]: cannot apply unary operator `-` to type `u32`
|
error[E0600]: cannot apply unary operator `-` to type `u32`
|
||||||
--> $DIR/default_value_t_invalid.rs:14:44
|
--> tests/derive_ui/default_value_t_invalid.rs:14:30
|
||||||
|
|
|
|
||||||
14 | #[clap(value_parser, default_value_t = -10)]
|
14 | #[clap(default_value_t = -10)]
|
||||||
| ^^^ cannot apply unary operator `-`
|
| ^^^ cannot apply unary operator `-`
|
||||||
|
|
|
|
||||||
= note: unsigned values cannot be negated
|
= note: unsigned values cannot be negated
|
||||||
|
|
|
@ -10,9 +10,9 @@ use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct DaemonOpts {
|
struct DaemonOpts {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
user: String,
|
user: String,
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
group: String,
|
group: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use clap::Parser;
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "make-cookie")]
|
#[clap(name = "make-cookie")]
|
||||||
struct MakeCookie {
|
struct MakeCookie {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
|
|
||||||
#[clap(skip, flatten)]
|
#[clap(skip, flatten)]
|
||||||
|
@ -22,13 +22,10 @@ struct MakeCookie {
|
||||||
enum Command {
|
enum Command {
|
||||||
#[clap(name = "pound")]
|
#[clap(name = "pound")]
|
||||||
/// Pound acorns into flour for cookie dough.
|
/// Pound acorns into flour for cookie dough.
|
||||||
Pound {
|
Pound { acorns: u32 },
|
||||||
#[clap(value_parser)]
|
|
||||||
acorns: u32,
|
|
||||||
},
|
|
||||||
|
|
||||||
Sparkle {
|
Sparkle {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
color: String,
|
color: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use clap::Parser;
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "make-cookie")]
|
#[clap(name = "make-cookie")]
|
||||||
struct MakeCookie {
|
struct MakeCookie {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
|
|
||||||
#[clap(subcommand, skip)]
|
#[clap(subcommand, skip)]
|
||||||
|
@ -22,13 +22,10 @@ struct MakeCookie {
|
||||||
enum Command {
|
enum Command {
|
||||||
#[clap(name = "pound")]
|
#[clap(name = "pound")]
|
||||||
/// Pound acorns into flour for cookie dough.
|
/// Pound acorns into flour for cookie dough.
|
||||||
Pound {
|
Pound { acorns: u32 },
|
||||||
#[clap(value_parser)]
|
|
||||||
acorns: u32,
|
|
||||||
},
|
|
||||||
|
|
||||||
Sparkle {
|
Sparkle {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
color: String,
|
color: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ enum Kind {
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "test")]
|
#[clap(name = "test")]
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
number: u32,
|
number: u32,
|
||||||
#[clap(skip)]
|
#[clap(skip)]
|
||||||
k: Kind,
|
k: Kind,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use clap::Parser;
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "basic", subcommand)]
|
#[clap(name = "basic", subcommand)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct MakeCookie {
|
struct MakeCookie {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
|
|
||||||
#[clap(subcommand, flatten)]
|
#[clap(subcommand, flatten)]
|
||||||
|
@ -20,13 +20,10 @@ struct MakeCookie {
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Pound acorns into flour for cookie dough.
|
/// Pound acorns into flour for cookie dough.
|
||||||
Pound {
|
Pound { acorns: u32 },
|
||||||
#[clap(value_parser)]
|
|
||||||
acorns: u32,
|
|
||||||
},
|
|
||||||
|
|
||||||
Sparkle {
|
Sparkle {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
color: String,
|
color: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct MakeCookie {
|
struct MakeCookie {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
|
|
||||||
#[clap(subcommand, long)]
|
#[clap(subcommand, long)]
|
||||||
|
@ -20,13 +20,10 @@ struct MakeCookie {
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Pound acorns into flour for cookie dough.
|
/// Pound acorns into flour for cookie dough.
|
||||||
Pound {
|
Pound { acorns: u32 },
|
||||||
#[clap(value_parser)]
|
|
||||||
acorns: u32,
|
|
||||||
},
|
|
||||||
|
|
||||||
Sparkle {
|
Sparkle {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
color: String,
|
color: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct MakeCookie {
|
struct MakeCookie {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
|
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
|
@ -20,13 +20,10 @@ struct MakeCookie {
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Pound acorns into flour for cookie dough.
|
/// Pound acorns into flour for cookie dough.
|
||||||
Pound {
|
Pound { acorns: u32 },
|
||||||
#[clap(value_parser)]
|
|
||||||
acorns: u32,
|
|
||||||
},
|
|
||||||
|
|
||||||
Sparkle {
|
Sparkle {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
color: String,
|
color: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct MakeCookie {
|
struct MakeCookie {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
s: String,
|
s: String,
|
||||||
|
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
|
@ -20,13 +20,10 @@ struct MakeCookie {
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Pound acorns into flour for cookie dough.
|
/// Pound acorns into flour for cookie dough.
|
||||||
Pound {
|
Pound { acorns: u32 },
|
||||||
#[clap(value_parser)]
|
|
||||||
acorns: u32,
|
|
||||||
},
|
|
||||||
|
|
||||||
Sparkle {
|
Sparkle {
|
||||||
#[clap(short, value_parser)]
|
#[clap(short)]
|
||||||
color: String,
|
color: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue