mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
refactor(Arg): changes Arg::short to accept a char instead of &str
Closes #1303
This commit is contained in:
parent
ab8c97e3f1
commit
94872e00a5
35 changed files with 490 additions and 448 deletions
22
README.md
22
README.md
|
@ -200,7 +200,7 @@ fn main() {
|
|||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.about("Does awesome things")
|
||||
.arg(Arg::with_name("config")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.value_name("FILE")
|
||||
.help("Sets a custom config file")
|
||||
|
@ -210,7 +210,7 @@ fn main() {
|
|||
.required(true)
|
||||
.index(1))
|
||||
.arg(Arg::with_name("v")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.multiple(true)
|
||||
.help("Sets the level of verbosity"))
|
||||
.subcommand(SubCommand::with_name("test")
|
||||
|
@ -218,7 +218,7 @@ fn main() {
|
|||
.version("1.3")
|
||||
.author("Someone E. <someone_else@other.com>")
|
||||
.arg(Arg::with_name("debug")
|
||||
.short("d")
|
||||
.short('d')
|
||||
.help("print debug information verbosely")))
|
||||
.get_matches();
|
||||
|
||||
|
@ -321,7 +321,7 @@ subcommands:
|
|||
|
||||
Since this feature requires additional dependencies that not everyone may want, it is *not* compiled in by default and we need to enable a feature flag in Cargo.toml:
|
||||
|
||||
Simply change your `clap = "3.0.0-alpha1"` to `clap = {version = "3.0.0-alpha1", features = ["yaml"]}`.
|
||||
Simply change your `clap = "3.0.0-alpha.1"` to `clap = {version = "3.0.0-alpha.1", features = ["yaml"]}`.
|
||||
|
||||
Finally we create our `main.rs` file just like we would have with the previous two examples:
|
||||
|
||||
|
@ -418,7 +418,7 @@ To test out `clap`'s default auto-generated help/version follow these steps:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
clap = "3.0.0-alpha1"
|
||||
clap = "3.0.0-alpha.1"
|
||||
```
|
||||
|
||||
* Add the following to your `src/main.rs`
|
||||
|
@ -441,7 +441,7 @@ For full usage, add `clap` as a dependency in your `Cargo.toml` () to use from c
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
clap = "~3.0.0-alpha1"
|
||||
clap = "~3.0.0-alpha.1"
|
||||
```
|
||||
|
||||
(**note**: If you are concerned with supporting a minimum version of Rust that is *older* than the current stable Rust minus 2 stable releases, it's recommended to use the `~major.minor.patch` style versions in your `Cargo.toml` which will only update the patch version automatically. For more information see the [Compatibility Policy](#compatibility-policy))
|
||||
|
@ -464,7 +464,7 @@ To disable these, add this to your `Cargo.toml`:
|
|||
|
||||
```toml
|
||||
[dependencies.clap]
|
||||
version = "3.0.0-alpha1"
|
||||
version = "3.0.0-alpha.1"
|
||||
default-features = false
|
||||
```
|
||||
|
||||
|
@ -472,7 +472,7 @@ You can also selectively enable only the features you'd like to include, by addi
|
|||
|
||||
```toml
|
||||
[dependencies.clap]
|
||||
version = "3.0.0-alpha1"
|
||||
version = "3.0.0-alpha.1"
|
||||
default-features = false
|
||||
|
||||
# Cherry-pick the features you'd like to use
|
||||
|
@ -521,7 +521,7 @@ In order to keep from being surprised of breaking changes, it is **highly** reco
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
clap = "~3.0.0-alpha1"
|
||||
clap = "~3.0.0-alpha.1"
|
||||
```
|
||||
|
||||
This will cause *only* the patch version to be updated upon a `cargo update` call, and therefore cannot break due to new features, or bumped minimum versions of Rust.
|
||||
|
@ -538,11 +538,11 @@ Right now Cargo's version resolution is pretty naive, it's just a brute-force se
|
|||
|
||||
# In one Cargo.toml
|
||||
[dependencies]
|
||||
clap = "~3.0.0-alpha1"
|
||||
clap = "~3.0.0-alpha.1"
|
||||
|
||||
# In another Cargo.toml
|
||||
[dependencies]
|
||||
clap = "3.0.0-alpha1"
|
||||
clap = "3.0.0-alpha.1"
|
||||
```
|
||||
|
||||
This is inherently an unresolvable crate graph in Cargo right now. Cargo requires there's only one major version of a crate, and being in the same workspace these two crates must share a version. This is impossible in this location, though, as these version constraints cannot be met.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
extern crate clap;
|
||||
extern crate test;
|
||||
|
||||
use clap::{App, AppSettings, Arg, SubCommand, ArgSettings};
|
||||
use clap::{App, AppSettings, Arg, ArgSettings, SubCommand};
|
||||
|
||||
use test::Bencher;
|
||||
|
||||
|
@ -14,32 +14,39 @@ static OPT3_VALS: [&'static str; 2] = ["fast", "slow"];
|
|||
static POS3_VALS: [&'static str; 2] = ["vi", "emacs"];
|
||||
|
||||
macro_rules! create_app {
|
||||
() => ({
|
||||
() => {{
|
||||
App::new("claptests")
|
||||
.version("0.1")
|
||||
.about("tests clap library")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.args_from_usage(ARGS)
|
||||
.arg(Arg::from("-f --flag... 'tests flags'")
|
||||
.setting(ArgSettings::Global))
|
||||
.args(&[
|
||||
Arg::from("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("option2"),
|
||||
Arg::from("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
|
||||
Arg::from("[positional2] 'tests positionals with exclusions'"),
|
||||
Arg::from("-O --Option [option3] 'tests options with specific value sets'").possible_values(&OPT3_VALS),
|
||||
Arg::from("[positional3]... 'tests positionals with specific values'").possible_values(&POS3_VALS),
|
||||
Arg::from("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
|
||||
Arg::from("--multvalsmo... [one] [two] 'Tests mutliple values, not mult occs'"),
|
||||
Arg::from("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
|
||||
Arg::from("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
|
||||
])
|
||||
.subcommand(SubCommand::with_name("subcmd")
|
||||
.about("tests subcommands")
|
||||
.version("0.1")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.arg_from_usage("-o --option [scoption]... 'tests options'")
|
||||
.arg_from_usage("[scpositional] 'tests positionals'"))
|
||||
})
|
||||
.version("0.1")
|
||||
.about("tests clap library")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.args_from_usage(ARGS)
|
||||
.arg(Arg::from("-f --flag... 'tests flags'").setting(ArgSettings::Global))
|
||||
.args(&[
|
||||
Arg::from("[flag2] -F 'tests flags with exclusions'")
|
||||
.conflicts_with("flag")
|
||||
.requires("option2"),
|
||||
Arg::from("--long-option-2 [option2] 'tests long options with exclusions'")
|
||||
.conflicts_with("option")
|
||||
.requires("positional2"),
|
||||
Arg::from("[positional2] 'tests positionals with exclusions'"),
|
||||
Arg::from("-O --Option [option3] 'tests options with specific value sets'")
|
||||
.possible_values(&OPT3_VALS),
|
||||
Arg::from("[positional3]... 'tests positionals with specific values'")
|
||||
.possible_values(&POS3_VALS),
|
||||
Arg::from("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
|
||||
Arg::from("--multvalsmo... [one] [two] 'Tests mutliple values, not mult occs'"),
|
||||
Arg::from("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
|
||||
Arg::from("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3),
|
||||
])
|
||||
.subcommand(
|
||||
SubCommand::with_name("subcmd")
|
||||
.about("tests subcommands")
|
||||
.version("0.1")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.arg_from_usage("-o --option [scoption]... 'tests options'")
|
||||
.arg_from_usage("[scpositional] 'tests positionals'"),
|
||||
)
|
||||
}};
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -55,7 +62,7 @@ fn create_app_builder(b: &mut Bencher) {
|
|||
.arg(
|
||||
Arg::with_name("opt")
|
||||
.help("tests options")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.long("option")
|
||||
.setting(ArgSettings::MultipleValues)
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
|
@ -67,14 +74,14 @@ fn create_app_builder(b: &mut Bencher) {
|
|||
)
|
||||
.arg(
|
||||
Arg::with_name("flag")
|
||||
.short("f")
|
||||
.short('f')
|
||||
.help("tests flags")
|
||||
.long("flag")
|
||||
.settings(&[ArgSettings::MultipleOccurrences, ArgSettings::Global]),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("flag2")
|
||||
.short("F")
|
||||
.short('F')
|
||||
.help("tests flags with exclusions")
|
||||
.conflicts_with("flag")
|
||||
.requires("option2"),
|
||||
|
@ -94,7 +101,7 @@ fn create_app_builder(b: &mut Bencher) {
|
|||
)
|
||||
.arg(
|
||||
Arg::with_name("option3")
|
||||
.short("O")
|
||||
.short('O')
|
||||
.long("Option")
|
||||
.setting(ArgSettings::TakesValue)
|
||||
.help("tests options with specific value sets")
|
||||
|
@ -145,7 +152,7 @@ fn create_app_builder(b: &mut Bencher) {
|
|||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.arg(
|
||||
Arg::with_name("scoption")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.long("option")
|
||||
.setting(ArgSettings::MultipleValues)
|
||||
.setting(ArgSettings::MultipleOccurrences)
|
||||
|
|
|
@ -46,13 +46,13 @@ fn app_example3<'b, 'c>() -> App<'b, 'c> {
|
|||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.help("turn on debugging information")
|
||||
.short("d"),
|
||||
.short('d'),
|
||||
)
|
||||
.args(&[
|
||||
Arg::with_name("config")
|
||||
.help("sets the config file to use")
|
||||
.setting(ArgSettings::TakesValue)
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config"),
|
||||
Arg::with_name("input")
|
||||
.help("the input file to use")
|
||||
|
@ -74,13 +74,13 @@ fn app_example4<'b, 'c>() -> App<'b, 'c> {
|
|||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.help("turn on debugging information")
|
||||
.short("d")
|
||||
.short('d')
|
||||
.long("debug"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("config")
|
||||
.help("sets the config file to use")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -95,7 +95,7 @@ fn app_example5<'b, 'c>() -> App<'b, 'c> {
|
|||
App::new("MyApp").arg(
|
||||
Arg::with_name("awesome")
|
||||
.help("turns up the awesome")
|
||||
.short("a")
|
||||
.short('a')
|
||||
.long("awesome")
|
||||
.setting(ArgSettings::MultipleOccurrences)
|
||||
.requires("config")
|
||||
|
@ -132,7 +132,7 @@ fn app_example7<'b, 'c>() -> App<'b, 'c> {
|
|||
ArgSettings::MultipleOccurrences,
|
||||
ArgSettings::Required,
|
||||
])
|
||||
.short("i")
|
||||
.short('i')
|
||||
.long("input")
|
||||
.requires("config")
|
||||
.conflicts_with("output"),
|
||||
|
@ -151,7 +151,7 @@ fn app_example8<'b, 'c>() -> App<'b, 'c> {
|
|||
ArgSettings::MultipleOccurrences,
|
||||
ArgSettings::Required,
|
||||
])
|
||||
.short("i")
|
||||
.short('i')
|
||||
.long("input")
|
||||
.requires("config")
|
||||
.conflicts_with("output"),
|
||||
|
@ -162,7 +162,7 @@ fn app_example10<'b, 'c>() -> App<'b, 'c> {
|
|||
App::new("myapp").about("does awesome things").arg(
|
||||
Arg::with_name("CONFIG")
|
||||
.help("The config file to use (default is \"config.json\")")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.setting(ArgSettings::TakesValue),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -292,9 +292,9 @@ where
|
|||
.help_template(TEMPLATE)
|
||||
// Handle help/version manually to make their output formatting
|
||||
// consistent with short/long views.
|
||||
.arg(arg("help-short").short("h"))
|
||||
.arg(arg("help-short").short('h'))
|
||||
.arg(flag("help"))
|
||||
.arg(flag("version").short("V"))
|
||||
.arg(flag("version").short('V'))
|
||||
// First, set up primary positional/flag arguments.
|
||||
.arg(arg("pattern")
|
||||
.required_unless_one(&[
|
||||
|
@ -302,7 +302,7 @@ where
|
|||
"version",
|
||||
]))
|
||||
.arg(arg("path").setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(flag("regexp").short("e")
|
||||
.arg(flag("regexp").short('e')
|
||||
.settings(&[
|
||||
ArgSettings::AllowHyphenValues,
|
||||
ArgSettings::MultipleOccurrences,
|
||||
|
@ -315,52 +315,52 @@ where
|
|||
.arg(flag("type-list")
|
||||
.conflicts_with_all(&["file", "files", "pattern", "regexp"]))
|
||||
// Second, set up common flags.
|
||||
.arg(flag("text").short("a"))
|
||||
.arg(flag("count").short("c"))
|
||||
.arg(flag("text").short('a'))
|
||||
.arg(flag("count").short('c'))
|
||||
.arg(flag("color")
|
||||
.value_name("WHEN")
|
||||
.setting(ArgSettings::HidePossibleValues)
|
||||
.possible_values(&["never", "auto", "always", "ansi"]))
|
||||
.arg(flag("colors").value_name("SPEC")
|
||||
.settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue]))
|
||||
.arg(flag("fixed-strings").short("F"))
|
||||
.arg(flag("glob").short("g")
|
||||
.arg(flag("fixed-strings").short('F'))
|
||||
.arg(flag("glob").short('g')
|
||||
.settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue])
|
||||
.value_name("GLOB"))
|
||||
.arg(flag("ignore-case").short("i"))
|
||||
.arg(flag("line-number").short("n"))
|
||||
.arg(flag("no-line-number").short("N"))
|
||||
.arg(flag("quiet").short("q"))
|
||||
.arg(flag("type").short("t")
|
||||
.arg(flag("ignore-case").short('i'))
|
||||
.arg(flag("line-number").short('n'))
|
||||
.arg(flag("no-line-number").short('N'))
|
||||
.arg(flag("quiet").short('q'))
|
||||
.arg(flag("type").short('t')
|
||||
.settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue])
|
||||
.value_name("TYPE"))
|
||||
.arg(flag("type-not").short("T")
|
||||
.arg(flag("type-not").short('T')
|
||||
.settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue])
|
||||
.value_name("TYPE"))
|
||||
.arg(flag("unrestricted").short("u")
|
||||
.arg(flag("unrestricted").short('u')
|
||||
.setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(flag("invert-match").short("v"))
|
||||
.arg(flag("word-regexp").short("w"))
|
||||
.arg(flag("invert-match").short('v'))
|
||||
.arg(flag("word-regexp").short('w'))
|
||||
// Third, set up less common flags.
|
||||
.arg(flag("after-context").short("A")
|
||||
.arg(flag("after-context").short('A')
|
||||
.value_name("NUM")
|
||||
.validator(validate_number))
|
||||
.arg(flag("before-context").short("B")
|
||||
.arg(flag("before-context").short('B')
|
||||
.value_name("NUM")
|
||||
.validator(validate_number))
|
||||
.arg(flag("context").short("C")
|
||||
.arg(flag("context").short('C')
|
||||
.value_name("NUM")
|
||||
.validator(validate_number))
|
||||
.arg(flag("column"))
|
||||
.arg(flag("context-separator")
|
||||
.value_name("SEPARATOR"))
|
||||
.arg(flag("debug"))
|
||||
.arg(flag("file").short("f")
|
||||
.arg(flag("file").short('f')
|
||||
.value_name("FILE")
|
||||
.setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(flag("files-with-matches").short("l"))
|
||||
.arg(flag("files-with-matches").short('l'))
|
||||
.arg(flag("files-without-match"))
|
||||
.arg(flag("with-filename").short("H"))
|
||||
.arg(flag("with-filename").short('H'))
|
||||
.arg(flag("no-filename"))
|
||||
.arg(flag("heading").overrides_with("no-heading"))
|
||||
.arg(flag("no-heading").overrides_with("heading"))
|
||||
|
@ -368,9 +368,9 @@ where
|
|||
.arg(flag("ignore-file")
|
||||
.value_name("FILE")
|
||||
.setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(flag("follow").short("L"))
|
||||
.arg(flag("follow").short('L'))
|
||||
.arg(flag("max-count")
|
||||
.short("m").value_name("NUM")
|
||||
.short('m').value_name("NUM")
|
||||
.validator(validate_number))
|
||||
.arg(flag("maxdepth")
|
||||
.value_name("NUM")
|
||||
|
@ -383,13 +383,13 @@ where
|
|||
.arg(flag("no-ignore-vcs"))
|
||||
.arg(flag("null"))
|
||||
.arg(flag("path-separator").value_name("SEPARATOR"))
|
||||
.arg(flag("pretty").short("p"))
|
||||
.arg(flag("replace").short("r").value_name("ARG"))
|
||||
.arg(flag("case-sensitive").short("s"))
|
||||
.arg(flag("smart-case").short("S"))
|
||||
.arg(flag("pretty").short('p'))
|
||||
.arg(flag("replace").short('r').value_name("ARG"))
|
||||
.arg(flag("case-sensitive").short('s'))
|
||||
.arg(flag("smart-case").short('S'))
|
||||
.arg(flag("sort-files"))
|
||||
.arg(flag("threads")
|
||||
.short("j").value_name("ARG")
|
||||
.short('j').value_name("ARG")
|
||||
.validator(validate_number))
|
||||
.arg(flag("vimgrep"))
|
||||
.arg(flag("type-add")
|
||||
|
|
|
@ -32,7 +32,7 @@ pub fn build_cli() -> App<'static, 'static> {
|
|||
// .setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.arg(Arg::with_name("verbose")
|
||||
.help("Enable verbose output")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.long("verbose"))
|
||||
.subcommand(SubCommand::with_name("show")
|
||||
.about("Show the active and installed toolchains")
|
||||
|
@ -214,7 +214,7 @@ pub fn build_cli() -> App<'static, 'static> {
|
|||
.about("Download and install updates to rustup"))
|
||||
.subcommand(SubCommand::with_name("uninstall")
|
||||
.about("Uninstall rustup.")
|
||||
.arg(Arg::with_name("no-prompt").short("y")))
|
||||
.arg(Arg::with_name("no-prompt").short('y')))
|
||||
.subcommand(SubCommand::with_name("upgrade-data")
|
||||
.about("Upgrade the internal data format.")))
|
||||
.subcommand(SubCommand::with_name("telemetry")
|
||||
|
|
|
@ -39,7 +39,7 @@ fn main() {
|
|||
.about("Does awesome things")
|
||||
.arg(
|
||||
Arg::with_name("config")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.value_name("FILE")
|
||||
.help("Sets a custom config file")
|
||||
|
@ -52,14 +52,14 @@ fn main() {
|
|||
)
|
||||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.short("d")
|
||||
.short('d')
|
||||
.multiple(true)
|
||||
.help("Turn debugging information on"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("test")
|
||||
.about("does testing things")
|
||||
.arg(Arg::with_name("list").short("l").help("lists test values")),
|
||||
.arg(Arg::with_name("list").short('l').help("lists test values")),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ fn main() {
|
|||
// A simple "Flag" argument example (i.e. "-d") using the builder pattern
|
||||
.arg(Arg::with_name("debug")
|
||||
.help("turn on debugging information")
|
||||
.short("d"))
|
||||
.short('d'))
|
||||
|
||||
// Two arguments, one "Option" argument (i.e. one that takes a value) such
|
||||
// as "-c some", and one positional argument (i.e. "myapp some_file")
|
||||
|
@ -39,7 +39,7 @@ fn main() {
|
|||
Arg::with_name("config")
|
||||
.help("sets the config file to use")
|
||||
.takes_value(true)
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config"),
|
||||
Arg::with_name("input")
|
||||
.help("the input file to use")
|
||||
|
|
|
@ -23,13 +23,13 @@ fn main() {
|
|||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.help("turn on debugging information")
|
||||
.short("d")
|
||||
.short('d')
|
||||
.long("debug"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("config")
|
||||
.help("sets the config file to use")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config"),
|
||||
)
|
||||
.arg(
|
||||
|
|
|
@ -18,7 +18,7 @@ fn main() {
|
|||
// you want for your individual case.
|
||||
.arg(Arg::with_name("awesome")
|
||||
.help("turns up the awesome") // Displayed when showing help info
|
||||
.short("a") // Trigger this arg with "-a"
|
||||
.short('a') // Trigger this arg with "-a"
|
||||
.long("awesome") // Trigger this arg with "--awesome"
|
||||
.multiple(true) // This flag should allow multiple
|
||||
// occurrences such as "-aaa" or "-a -a"
|
||||
|
|
|
@ -19,7 +19,7 @@ fn main() {
|
|||
.arg(Arg::with_name("input")
|
||||
.help("the input file to use") // Displayed when showing help info
|
||||
.takes_value(true) // MUST be set to true in order to be an "option" argument
|
||||
.short("i") // This argument is triggered with "-i"
|
||||
.short('i') // This argument is triggered with "-i"
|
||||
.long("input") // This argument is triggered with "--input"
|
||||
.multiple(true) // Set to true if you wish to allow multiple occurrences
|
||||
// such as "-i file -i other_file -i third_file"
|
||||
|
|
|
@ -3,13 +3,13 @@ extern crate clap;
|
|||
use clap::{App, Arg};
|
||||
|
||||
fn main() {
|
||||
// There are two ways in which to get a default value, one is to use claps Arg::default_value
|
||||
// method, and the other is to use Rust's built in Option::unwrap_or method.
|
||||
//
|
||||
// I'll demo both here.
|
||||
//
|
||||
// First, we'll use clap's Arg::default_value with an "INPUT" file.
|
||||
let matches = App::new("myapp").about("does awesome things")
|
||||
// There are two ways in which to get a default value, one is to use claps Arg::default_value
|
||||
// method, and the other is to use Rust's built in Option::unwrap_or method.
|
||||
//
|
||||
// I'll demo both here.
|
||||
//
|
||||
// First, we'll use clap's Arg::default_value with an "INPUT" file.
|
||||
let matches = App::new("myapp").about("does awesome things")
|
||||
.arg(Arg::with_name("INPUT")
|
||||
.help("The input file to use") // Note, we don't need to specify
|
||||
// anything like, "Defaults to..."
|
||||
|
@ -24,17 +24,17 @@ fn main() {
|
|||
// Note that we have to manaully include some verbage to the user
|
||||
// telling them what the default will be.
|
||||
.help("The config file to use (default is \"config.json\")")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.takes_value(true))
|
||||
.get_matches();
|
||||
|
||||
// It's safe to call unwrap because the value with either be what the user input at runtime
|
||||
// or "input.txt"
|
||||
let input = matches.value_of("INPUT").unwrap();
|
||||
// It's safe to call unwrap because the value with either be what the user input at runtime
|
||||
// or "input.txt"
|
||||
let input = matches.value_of("INPUT").unwrap();
|
||||
|
||||
// Using Option::unwrap_or we get the same affect, but without the added help text injection
|
||||
let config_file = matches.value_of("CONFIG").unwrap_or("config.json");
|
||||
// Using Option::unwrap_or we get the same affect, but without the added help text injection
|
||||
let config_file = matches.value_of("CONFIG").unwrap_or("config.json");
|
||||
|
||||
println!("The input file is: {}", input);
|
||||
println!("The config file is: {}", config_file);
|
||||
println!("The input file is: {}", input);
|
||||
println!("The config file is: {}", config_file);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ fn main() {
|
|||
// Now let's assume we have a -c [config] argument which requires one of
|
||||
// (but **not** both) the "input" arguments
|
||||
.arg(Arg::with_name("config")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.takes_value(true)
|
||||
.requires("input"))
|
||||
.get_matches();
|
||||
|
|
|
@ -5,8 +5,8 @@ use clap::{App, Arg};
|
|||
/// myprog -f -p=bob -- sloppy slop slop
|
||||
fn main() {
|
||||
let matches = App::new("myprog")
|
||||
.arg(Arg::with_name("eff").short("f"))
|
||||
.arg(Arg::with_name("pea").short("p").takes_value(true))
|
||||
.arg(Arg::with_name("eff").short('f'))
|
||||
.arg(Arg::with_name("pea").short('p').takes_value(true))
|
||||
.arg(Arg::with_name("slop").multiple(true).last(true))
|
||||
.get_matches();
|
||||
|
||||
|
|
|
@ -619,7 +619,7 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
/// // Adding a single "flag" argument with a short and help text, using Arg::with_name()
|
||||
/// .arg(
|
||||
/// Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .help("turns on debugging mode")
|
||||
/// )
|
||||
/// // Adding a single "option" argument with a short, a long, and help text using the less
|
||||
|
@ -968,8 +968,8 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
///
|
||||
/// let mut app = App::new("foo")
|
||||
/// .arg(Arg::with_name("bar")
|
||||
/// .short("b"))
|
||||
/// .mut_arg("bar", |a| a.short("B"));
|
||||
/// .short('b'))
|
||||
/// .mut_arg("bar", |a| a.short('B'));
|
||||
///
|
||||
/// let res = app.try_get_matches_from_mut(vec!["foo", "-b"]);
|
||||
///
|
||||
|
|
|
@ -2,23 +2,23 @@ mod settings;
|
|||
pub use self::settings::{ArgFlags, ArgSettings};
|
||||
|
||||
// Std
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
#[cfg(any(target_os = "windows", target_arch = "wasm32"))]
|
||||
use osstringext::OsStrExt3;
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::{Ord, Ordering};
|
||||
use std::env;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::env;
|
||||
use std::cmp::{Ord, Ordering};
|
||||
use std::rc::Rc;
|
||||
use std::str;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
// Third Party
|
||||
// Third Party
|
||||
use util::VecMap;
|
||||
#[cfg(feature = "yaml")]
|
||||
use yaml_rust;
|
||||
use util::VecMap;
|
||||
|
||||
// Internal
|
||||
use build::UsageParser;
|
||||
|
@ -37,7 +37,7 @@ use INTERNAL_ERROR_MSG;
|
|||
/// # use clap::Arg;
|
||||
/// // Using the traditional builder pattern and setting each option manually
|
||||
/// let cfg = Arg::with_name("config")
|
||||
/// .short("c")
|
||||
/// .short('c')
|
||||
/// .long("config")
|
||||
/// .takes_value(true)
|
||||
/// .value_name("FILE")
|
||||
|
@ -224,18 +224,15 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// arguments, in which case `clap` simply will not assign those to the auto-generated
|
||||
/// `version` or `help` arguments.
|
||||
///
|
||||
/// **NOTE:** Any leading `-` characters will be stripped, and only the first
|
||||
/// non `-` character will be used as the [`short`] version
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// To set [`short`] use a single valid UTF-8 code point. If you supply a leading `-` such as
|
||||
/// To set [`short`] use a single valid UTF-8 character. If you supply a leading `-` such as
|
||||
/// `-c`, the `-` will be stripped.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// Arg::with_name("config")
|
||||
/// .short("c")
|
||||
/// .short('c')
|
||||
/// # ;
|
||||
/// ```
|
||||
///
|
||||
|
@ -245,7 +242,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("config")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-c"
|
||||
/// ]);
|
||||
|
@ -253,8 +250,8 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// assert!(m.is_present("config"));
|
||||
/// ```
|
||||
/// [`short`]: ./struct.Arg.html#method.short
|
||||
pub fn short<S: AsRef<str>>(mut self, s: S) -> Self {
|
||||
self.short = s.as_ref().trim_left_matches(|c| c == '-').chars().nth(0);
|
||||
pub fn short(mut self, s: char) -> Self {
|
||||
self.short = Some(s);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -639,7 +636,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("dbg")
|
||||
/// .long("debug"))
|
||||
/// .arg(Arg::with_name("infile")
|
||||
/// .short("i")
|
||||
/// .short('i')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "--debug", "-i", "file"
|
||||
|
@ -661,7 +658,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("dbg")
|
||||
/// .long("debug"))
|
||||
/// .arg(Arg::with_name("infile")
|
||||
/// .short("i")
|
||||
/// .short('i')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog"
|
||||
|
@ -714,7 +711,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("dbg")
|
||||
/// .long("debug"))
|
||||
/// .arg(Arg::with_name("infile")
|
||||
/// .short("i")
|
||||
/// .short('i')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "--debug"
|
||||
|
@ -736,7 +733,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("dbg")
|
||||
/// .long("debug"))
|
||||
/// .arg(Arg::with_name("infile")
|
||||
/// .short("i")
|
||||
/// .short('i')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog"
|
||||
|
@ -1501,7 +1498,6 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
self
|
||||
}
|
||||
|
||||
|
||||
/// Specifies a value that *stops* parsing multiple values of a give argument. By default when
|
||||
/// one sets [`multiple(true)`] on an argument, clap will continue parsing values for that
|
||||
/// argument until it reaches another valid argument, or one of the other more specific settings
|
||||
|
@ -1770,7 +1766,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// Arg::with_name("file")
|
||||
/// .short("f")
|
||||
/// .short('f')
|
||||
/// .number_of_values(3)
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -1783,7 +1779,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("file")
|
||||
/// .takes_value(true)
|
||||
/// .number_of_values(2)
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "-F", "file1"
|
||||
/// ]);
|
||||
|
@ -1835,10 +1831,13 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// [`Err(String)`]: https://doc.rust-lang.org/std/result/enum.Result.html#variant.Err
|
||||
/// [`Rc`]: https://doc.rust-lang.org/std/rc/struct.Rc.html
|
||||
pub fn validator<F, O, E>(mut self, f: F) -> Self
|
||||
where F: Fn(String) -> Result<O, E> + 'static,
|
||||
E: ToString
|
||||
where
|
||||
F: Fn(String) -> Result<O, E> + 'static,
|
||||
E: ToString,
|
||||
{
|
||||
self.validator = Some(Rc::new(move |s| f(s).map(|_| ()).map_err(|e| e.to_string())));
|
||||
self.validator = Some(Rc::new(move |s| {
|
||||
f(s).map(|_| ()).map_err(|e| e.to_string())
|
||||
}));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -1895,7 +1894,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// Arg::with_name("file")
|
||||
/// .short("f")
|
||||
/// .short('f')
|
||||
/// .max_values(3)
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -1908,7 +1907,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("file")
|
||||
/// .takes_value(true)
|
||||
/// .max_values(3)
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "-F", "file1", "file2"
|
||||
/// ]);
|
||||
|
@ -1927,7 +1926,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("file")
|
||||
/// .takes_value(true)
|
||||
/// .max_values(2)
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "-F", "file1", "file2", "file3"
|
||||
/// ]);
|
||||
|
@ -1959,7 +1958,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// Arg::with_name("file")
|
||||
/// .short("f")
|
||||
/// .short('f')
|
||||
/// .min_values(3)
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -1972,7 +1971,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("file")
|
||||
/// .takes_value(true)
|
||||
/// .min_values(2)
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "-F", "file1", "file2", "file3"
|
||||
/// ]);
|
||||
|
@ -1991,7 +1990,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// .arg(Arg::with_name("file")
|
||||
/// .takes_value(true)
|
||||
/// .min_values(2)
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from_safe(vec![
|
||||
/// "prog", "-F", "file1"
|
||||
/// ]);
|
||||
|
@ -2017,7 +2016,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("config")
|
||||
/// .short("c")
|
||||
/// .short('c')
|
||||
/// .long("config")
|
||||
/// .value_delimiter(";"))
|
||||
/// .get_matches_from(vec![
|
||||
|
@ -2065,7 +2064,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// Arg::with_name("speed")
|
||||
/// .short("s")
|
||||
/// .short('s')
|
||||
/// .value_names(&["fast", "slow"])
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -2621,12 +2620,12 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// // Args without a display_order have a value of 999 and are
|
||||
/// // displayed alphabetically with all other 999 valued args.
|
||||
/// .long("long-option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true)
|
||||
/// .help("Some help and text"))
|
||||
/// .arg(Arg::with_name("b")
|
||||
/// .long("other-option")
|
||||
/// .short("O")
|
||||
/// .short('O')
|
||||
/// .takes_value(true)
|
||||
/// .display_order(1) // In order to force this arg to appear *first*
|
||||
/// // all we have to do is give it a value lower than 999.
|
||||
|
@ -2988,7 +2987,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .setting(ArgSettings::Global)
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -3002,7 +3001,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("verb")
|
||||
/// .long("verbose")
|
||||
/// .short("v")
|
||||
/// .short('v')
|
||||
/// .setting(ArgSettings::Global))
|
||||
/// .subcommand(SubCommand::with_name("test"))
|
||||
/// .subcommand(SubCommand::with_name("do-stuff"))
|
||||
|
@ -3049,7 +3048,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// let delims = App::new("prog")
|
||||
/// .arg(Arg::with_name("opt")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .settings(&[ArgSettings::RequireDelimiter, ArgSettings::MultipleValues]))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-o", "val1,val2,val3",
|
||||
|
@ -3064,7 +3063,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// # use clap::{App, Arg, ErrorKind, ArgSettings};
|
||||
/// let res = App::new("prog")
|
||||
/// .arg(Arg::with_name("opt")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .setting(ArgSettings::RequireDelimiter))
|
||||
/// .try_get_matches_from(vec![
|
||||
/// "prog", "-o", "val1", "val2", "val3",
|
||||
|
@ -3085,7 +3084,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// let delims = App::new("prog")
|
||||
/// .arg(Arg::with_name("opt")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .setting(ArgSettings::MultipleValues))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-o", "val1", "val2", "val3",
|
||||
|
@ -3180,7 +3179,10 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
}
|
||||
|
||||
/// **Deprecated**
|
||||
#[deprecated(since="2.30.0", note="Use `Arg::setting(ArgSettings::AllowEmptyValues)` instead. Will be removed in v3.0-beta")]
|
||||
#[deprecated(
|
||||
since = "2.30.0",
|
||||
note = "Use `Arg::setting(ArgSettings::AllowEmptyValues)` instead. Will be removed in v3.0-beta"
|
||||
)]
|
||||
pub fn empty_values(mut self, ev: bool) -> Self {
|
||||
if ev {
|
||||
self.setting(ArgSettings::AllowEmptyValues)
|
||||
|
@ -3266,7 +3268,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// let m = App::new("pv")
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("-o")
|
||||
/// .short('o')
|
||||
/// .long("--option")
|
||||
/// .settings(&[ArgSettings::IgnoreCase, ArgSettings::MultipleValues])
|
||||
/// .possible_value("test123")
|
||||
|
@ -3399,7 +3401,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("opt")
|
||||
/// .long("long-option-flag")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .settings(&[ArgSettings::TakesValue, ArgSettings::NextLineHelp])
|
||||
/// .value_names(&["value1", "value2"])
|
||||
/// .help("Some really long help and complex\n\
|
||||
|
@ -3492,7 +3494,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .setting(ArgSettings::MultipleValues)
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -3503,7 +3505,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("verbose")
|
||||
/// .setting(ArgSettings::MultipleOccurrences)
|
||||
/// .short("v"))
|
||||
/// .short('v'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-v", "-v", "-v" // note, -vvv would have same result
|
||||
/// ]);
|
||||
|
@ -3519,7 +3521,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("file")
|
||||
/// .setting(ArgSettings::MultipleValues) // implies TakesValue
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-F", "file1", "file2", "file3"
|
||||
/// ]);
|
||||
|
@ -3536,7 +3538,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let res = App::new("prog")
|
||||
/// .arg(Arg::with_name("file")
|
||||
/// .setting(ArgSettings::MultipleValues) // implies TakesValue
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .try_get_matches_from(vec![
|
||||
/// "prog", "-F", "file1", "-F", "file2", "-F", "file3"
|
||||
/// ]);
|
||||
|
@ -3552,7 +3554,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("file")
|
||||
/// .setting(ArgSettings::MultipleValues) // implies TakesValue
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .arg(Arg::with_name("word")
|
||||
/// .index(1))
|
||||
/// .get_matches_from(vec![
|
||||
|
@ -3576,7 +3578,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("file")
|
||||
/// .settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue])
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .arg(Arg::with_name("word")
|
||||
/// .index(1))
|
||||
/// .get_matches_from(vec![
|
||||
|
@ -3596,7 +3598,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let res = App::new("prog")
|
||||
/// .arg(Arg::with_name("file")
|
||||
/// .settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue])
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .arg(Arg::with_name("word")
|
||||
/// .index(1))
|
||||
/// .try_get_matches_from(vec![
|
||||
|
@ -3650,7 +3652,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let res = App::new("prog")
|
||||
/// .arg(Arg::with_name("cfg")
|
||||
/// .long("config")
|
||||
/// .short("v")
|
||||
/// .short('v')
|
||||
/// .setting(ArgSettings::TakesValue))
|
||||
/// .try_get_matches_from(vec![
|
||||
/// "prog", "--config="
|
||||
|
@ -3666,7 +3668,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let res = App::new("prog")
|
||||
/// .arg(Arg::with_name("cfg")
|
||||
/// .long("config")
|
||||
/// .short("v")
|
||||
/// .short('v')
|
||||
/// .setting(ArgSettings::AllowEmptyValues)) // implies TakesValue
|
||||
/// .try_get_matches_from(vec![
|
||||
/// "prog", "--config="
|
||||
|
@ -3697,7 +3699,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```rust
|
||||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .setting(ArgSettings::MultipleOccurrences)
|
||||
/// # ;
|
||||
/// ```
|
||||
|
@ -3708,7 +3710,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("verbose")
|
||||
/// .setting(ArgSettings::MultipleOccurrences)
|
||||
/// .short("v"))
|
||||
/// .short('v'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-v", "-v", "-v" // note, -vvv would have same result
|
||||
/// ]);
|
||||
|
@ -3724,7 +3726,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// let m = App::new("prog")
|
||||
/// .arg(Arg::with_name("file")
|
||||
/// .settings(&[ArgSettings::MultipleOccurrences, ArgSettings::TakesValue])
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "prog", "-F", "file1", "-F", "file2", "-F", "file3"
|
||||
/// ]);
|
||||
|
@ -3752,7 +3754,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
self.unset_setting(ArgSettings::MultipleOccurrences)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Indicates that all parameters passed after this should not be parsed
|
||||
/// individually, but rather passed in their entirety. It is worth noting
|
||||
/// that setting this requires all values to come after a `--` to indicate they
|
||||
|
@ -3772,9 +3774,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// [`Arg::allow_hyphen_values(true)`]: ./struct.Arg.html#method.allow_hyphen_values
|
||||
/// [`Arg::last(true)`]: ./struct.Arg.html#method.last
|
||||
/// [`AppSettings::TrailingVarArg`]: ./enum.AppSettings.html#variant.TrailingVarArg
|
||||
pub fn raw(self, raw: bool) -> Self {
|
||||
self.multiple(raw).allow_hyphen_values(raw).last(raw)
|
||||
}
|
||||
pub fn raw(self, raw: bool) -> Self { self.multiple(raw).allow_hyphen_values(raw).last(raw) }
|
||||
|
||||
/// Hides an argument from short help message output.
|
||||
///
|
||||
|
@ -3782,7 +3782,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
///
|
||||
/// **NOTE:** Setting this option will cause next-line-help output style to be used
|
||||
/// when long help (`--help`) is called.
|
||||
///
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
|
@ -3817,9 +3817,9 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// -h, --help Prints help information
|
||||
/// -V, --version Prints version information
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// However, when --help is called
|
||||
///
|
||||
///
|
||||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("prog")
|
||||
|
@ -3831,24 +3831,24 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// "prog", "--help"
|
||||
/// ]);
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// Then the following would be displayed
|
||||
///
|
||||
///
|
||||
/// ```notrust
|
||||
/// helptest
|
||||
///
|
||||
///
|
||||
/// USAGE:
|
||||
/// helptest [FLAGS]
|
||||
///
|
||||
///
|
||||
/// FLAGS:
|
||||
/// --config Some help text describing the --config arg
|
||||
/// -h, --help Prints help information
|
||||
/// -V, --version Prints version information
|
||||
/// ```
|
||||
pub fn hidden_short_help(self, hide: bool) -> Self {
|
||||
if hide {
|
||||
if hide {
|
||||
self.set(ArgSettings::HiddenShortHelp)
|
||||
} else {
|
||||
} else {
|
||||
self.unset(ArgSettings::HiddenShortHelp)
|
||||
}
|
||||
}
|
||||
|
@ -3859,7 +3859,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
///
|
||||
/// **NOTE:** Setting this option will cause next-line-help output style to be used
|
||||
/// when long help (`--help`) is called.
|
||||
///
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
|
@ -3894,9 +3894,9 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// -h, --help Prints help information
|
||||
/// -V, --version Prints version information
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// However, when -h is called
|
||||
///
|
||||
///
|
||||
/// ```rust
|
||||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("prog")
|
||||
|
@ -3908,15 +3908,15 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// "prog", "-h"
|
||||
/// ]);
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// Then the following would be displayed
|
||||
///
|
||||
///
|
||||
/// ```notrust
|
||||
/// helptest
|
||||
///
|
||||
///
|
||||
/// USAGE:
|
||||
/// helptest [FLAGS]
|
||||
///
|
||||
///
|
||||
/// FLAGS:
|
||||
/// --config Some help text describing the --config arg
|
||||
/// -h, --help Prints help information
|
||||
|
@ -3968,11 +3968,13 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
#[doc(hidden)]
|
||||
pub fn _build(&mut self) {
|
||||
if (self.is_set(ArgSettings::UseValueDelimiter)
|
||||
|| self.is_set(ArgSettings::RequireDelimiter)) && self.val_delim.is_none() {
|
||||
|| self.is_set(ArgSettings::RequireDelimiter)) && self.val_delim.is_none()
|
||||
{
|
||||
self.val_delim = Some(',');
|
||||
}
|
||||
if self.index.is_some() || (self.short.is_none() && self.long.is_none()) {
|
||||
if self.max_vals.is_some() || self.min_vals.is_some()
|
||||
if self.max_vals.is_some()
|
||||
|| self.min_vals.is_some()
|
||||
|| (self.num_vals.is_some() && self.num_vals.unwrap() > 1)
|
||||
{
|
||||
self.setb(ArgSettings::MultipleValues);
|
||||
|
@ -4006,11 +4008,13 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
// Used for positionals when printing
|
||||
#[doc(hidden)]
|
||||
pub fn multiple_str(&self) -> &str {
|
||||
let mult_vals = self.val_names
|
||||
let mult_vals = self
|
||||
.val_names
|
||||
.as_ref()
|
||||
.map_or(true, |names| names.len() < 2);
|
||||
if (self.is_set(ArgSettings::MultipleValues) || self.is_set(ArgSettings::MultipleOccurrences))
|
||||
&& mult_vals {
|
||||
if (self.is_set(ArgSettings::MultipleValues)
|
||||
|| self.is_set(ArgSettings::MultipleOccurrences)) && mult_vals
|
||||
{
|
||||
"..."
|
||||
} else {
|
||||
""
|
||||
|
@ -4050,29 +4054,35 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
// Deprecations
|
||||
// @TODO @v3-beta: remove
|
||||
impl<'a, 'b> Arg<'a, 'b> {
|
||||
|
||||
/// **Deprecated**
|
||||
#[deprecated(since="2.30.0", note="Renamed to `Arg::setting`. Will be removed in v3.0-beta")]
|
||||
#[deprecated(
|
||||
since = "2.30.0",
|
||||
note = "Renamed to `Arg::setting`. Will be removed in v3.0-beta"
|
||||
)]
|
||||
pub fn set(mut self, s: ArgSettings) -> Self {
|
||||
self.setb(s);
|
||||
self
|
||||
}
|
||||
|
||||
/// **Deprecated**
|
||||
#[deprecated(since="2.30.0", note="Renamed to `Arg::unset_setting`. Will be removed in v3.0-beta")]
|
||||
#[deprecated(
|
||||
since = "2.30.0",
|
||||
note = "Renamed to `Arg::unset_setting`. Will be removed in v3.0-beta"
|
||||
)]
|
||||
pub fn unset(mut self, s: ArgSettings) -> Self {
|
||||
self.unsetb(s);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
/// **Deprecated**
|
||||
#[deprecated(since="2.30.0", note="Use `Arg::from` instead. Will be removed in v3.0-beta")]
|
||||
#[deprecated(
|
||||
since = "2.30.0",
|
||||
note = "Use `Arg::from` instead. Will be removed in v3.0-beta"
|
||||
)]
|
||||
pub fn from_usage(u: &'a str) -> Self {
|
||||
let parser = UsageParser::from_usage(u);
|
||||
parser.parse()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'z> From<&'z Arg<'a, 'b>> for Arg<'a, 'b> {
|
||||
|
@ -4112,8 +4122,7 @@ impl<'n, 'e> Display for Arg<'n, 'e> {
|
|||
}
|
||||
if self.settings.is_set(ArgSettings::MultipleValues)
|
||||
&& (self.val_names.is_none()
|
||||
|| (self.val_names.is_some()
|
||||
&& self.val_names.as_ref().unwrap().len() == 1))
|
||||
|| (self.val_names.is_some() && self.val_names.as_ref().unwrap().len() == 1))
|
||||
{
|
||||
write!(f, "...")?;
|
||||
}
|
||||
|
@ -4197,9 +4206,7 @@ impl<'n, 'e> Ord for Arg<'n, 'e> {
|
|||
impl<'n, 'e> Eq for Arg<'n, 'e> {}
|
||||
|
||||
impl<'n, 'e> Hash for Arg<'n, 'e> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.name.hash(state);
|
||||
}
|
||||
fn hash<H: Hasher>(&self, state: &mut H) { self.name.hash(state); }
|
||||
}
|
||||
|
||||
impl<'n, 'e> fmt::Debug for Arg<'n, 'e> {
|
||||
|
@ -4249,9 +4256,9 @@ impl<'n, 'e> fmt::Debug for Arg<'n, 'e> {
|
|||
// Flags
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use util::VecMap;
|
||||
use build::ArgSettings;
|
||||
use super::Arg;
|
||||
use build::ArgSettings;
|
||||
use util::VecMap;
|
||||
|
||||
#[test]
|
||||
fn flag_display() {
|
||||
|
@ -4304,7 +4311,7 @@ mod test {
|
|||
#[test]
|
||||
fn option_display2() {
|
||||
let o2 = Arg::with_name("opt")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.value_names(&["file", "name"]);
|
||||
|
||||
assert_eq!(&*format!("{}", o2), "-o <file> <name>");
|
||||
|
@ -4313,7 +4320,7 @@ mod test {
|
|||
#[test]
|
||||
fn option_display3() {
|
||||
let o2 = Arg::with_name("opt")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.multiple(true)
|
||||
.value_names(&["file", "name"]);
|
||||
|
||||
|
|
|
@ -139,9 +139,9 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup};
|
||||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .arg("flag")
|
||||
/// .arg("color"))
|
||||
|
@ -171,9 +171,9 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup};
|
||||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"]))
|
||||
/// .get_matches_from(vec!["myprog", "-f"]);
|
||||
|
@ -201,9 +201,9 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup};
|
||||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"])
|
||||
/// .multiple(true))
|
||||
|
@ -218,9 +218,9 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
/// let result = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"]))
|
||||
/// .get_matches_from_safe(vec!["myprog", "-f", "-c"]);
|
||||
|
@ -254,9 +254,9 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
/// let result = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"])
|
||||
/// .required(true))
|
||||
|
@ -287,11 +287,11 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
/// let result = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d"))
|
||||
/// .short('d'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"])
|
||||
/// .requires("debug"))
|
||||
|
@ -326,13 +326,13 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
/// let result = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d"))
|
||||
/// .short('d'))
|
||||
/// .arg(Arg::with_name("verb")
|
||||
/// .short("v"))
|
||||
/// .short('v'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"])
|
||||
/// .requires_all(&["debug", "verb"]))
|
||||
|
@ -364,11 +364,11 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
/// let result = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d"))
|
||||
/// .short('d'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"])
|
||||
/// .conflicts_with("debug"))
|
||||
|
@ -400,13 +400,13 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
/// let result = App::new("myprog")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("color")
|
||||
/// .short("c"))
|
||||
/// .short('c'))
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d"))
|
||||
/// .short('d'))
|
||||
/// .arg(Arg::with_name("verb")
|
||||
/// .short("v"))
|
||||
/// .short('v'))
|
||||
/// .group(ArgGroup::with_name("req_flags")
|
||||
/// .args(&["flag", "color"])
|
||||
/// .conflicts_with_all(&["debug", "verb"]))
|
||||
|
|
55
src/lib.rs
55
src/lib.rs
|
@ -54,7 +54,7 @@
|
|||
//! .author("Kevin K. <kbknapp@gmail.com>")
|
||||
//! .about("Does awesome things")
|
||||
//! .arg(Arg::with_name("config")
|
||||
//! .short("c")
|
||||
//! .short('c')
|
||||
//! .long("config")
|
||||
//! .value_name("FILE")
|
||||
//! .help("Sets a custom config file")
|
||||
|
@ -64,7 +64,7 @@
|
|||
//! .required(true)
|
||||
//! .index(1))
|
||||
//! .arg(Arg::with_name("v")
|
||||
//! .short("v")
|
||||
//! .short('v')
|
||||
//! .multiple(true)
|
||||
//! .help("Sets the level of verbosity"))
|
||||
//! .subcommand(SubCommand::with_name("test")
|
||||
|
@ -72,7 +72,7 @@
|
|||
//! .version("1.3")
|
||||
//! .author("Someone E. <someone_else@other.com>")
|
||||
//! .arg(Arg::with_name("debug")
|
||||
//! .short("d")
|
||||
//! .short('d')
|
||||
//! .help("print debug information verbosely")))
|
||||
//! .get_matches();
|
||||
//!
|
||||
|
@ -517,15 +517,24 @@
|
|||
//! [license]: https://raw.githubusercontent.com/kbknapp/clap-rs/master/LICENSE-MIT
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![doc(html_root_url = "https://docs.rs/clap/3.0.0-alpha1")]
|
||||
#![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts,
|
||||
unused_import_braces, unused_allocation)]
|
||||
#![doc(html_root_url = "https://docs.rs/clap/3.0.0-alpha.1")]
|
||||
#![deny(
|
||||
missing_docs,
|
||||
missing_debug_implementations,
|
||||
missing_copy_implementations,
|
||||
trivial_casts,
|
||||
unused_import_braces,
|
||||
unused_allocation
|
||||
)]
|
||||
// @TODO @v3-beta: remove me!
|
||||
#![allow(deprecated)]
|
||||
// Lints we'd like to deny but are currently failing for upstream crates
|
||||
// unused_qualifications (bitflags, clippy)
|
||||
// trivial_numeric_casts (bitflags)
|
||||
#![cfg_attr(not(any(feature = "lints", feature = "nightly")), forbid(unstable_features))]
|
||||
#![cfg_attr(
|
||||
not(any(feature = "lints", feature = "nightly")),
|
||||
forbid(unstable_features)
|
||||
)]
|
||||
#![cfg_attr(feature = "lints", feature(plugin))]
|
||||
#![cfg_attr(feature = "lints", plugin(clippy))]
|
||||
// Need to disable deny(warnings) while deprecations are active
|
||||
|
@ -540,6 +549,10 @@ extern crate ansi_term;
|
|||
extern crate atty;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[cfg(feature = "derive")]
|
||||
#[cfg_attr(feature = "derive", allow(unused_imports))]
|
||||
#[cfg_attr(feature = "derive", macro_use)]
|
||||
extern crate clap_derive;
|
||||
extern crate indexmap;
|
||||
#[cfg(feature = "suggestions")]
|
||||
extern crate strsim;
|
||||
|
@ -551,18 +564,14 @@ extern crate unicode_width;
|
|||
extern crate vec_map;
|
||||
#[cfg(feature = "yaml")]
|
||||
extern crate yaml_rust;
|
||||
#[cfg(feature = "derive")]
|
||||
#[cfg_attr(feature = "derive", allow(unused_imports))]
|
||||
#[cfg_attr(feature = "derive", macro_use)]
|
||||
extern crate clap_derive;
|
||||
|
||||
#[cfg(feature = "yaml")]
|
||||
pub use yaml_rust::YamlLoader;
|
||||
pub use build::{Arg, ArgGroup, ArgSettings, App, AppSettings, Propagation};
|
||||
pub use parse::{OsValues, SubCommand, Values, ArgMatches};
|
||||
pub use build::{App, AppSettings, Arg, ArgGroup, ArgSettings, Propagation};
|
||||
pub use completions::Shell;
|
||||
pub use output::fmt::Format;
|
||||
pub use parse::errors::{Error, ErrorKind, Result};
|
||||
pub use completions::Shell;
|
||||
pub use parse::{ArgMatches, OsValues, SubCommand, Values};
|
||||
#[cfg(feature = "yaml")]
|
||||
pub use yaml_rust::YamlLoader;
|
||||
|
||||
#[cfg(feature = "derive")]
|
||||
#[cfg_attr(feature = "derive", doc(hidden))]
|
||||
|
@ -572,20 +581,18 @@ use std::result::Result as StdResult;
|
|||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod completions;
|
||||
mod parse;
|
||||
mod build;
|
||||
mod util;
|
||||
mod completions;
|
||||
mod output;
|
||||
mod parse;
|
||||
mod util;
|
||||
|
||||
const INTERNAL_ERROR_MSG: &'static str = "Fatal internal error. Please consider filing a bug \
|
||||
report at https://github.com/kbknapp/clap-rs/issues";
|
||||
const INVALID_UTF8: &'static str = "unexpected invalid UTF-8 code point";
|
||||
|
||||
/// @TODO @release @docs
|
||||
pub trait Clap: FromArgMatches + IntoApp + Sized {
|
||||
|
||||
}
|
||||
pub trait Clap: FromArgMatches + IntoApp + Sized {}
|
||||
|
||||
/// @TODO @release @docs
|
||||
pub trait FromArgMatches: Sized {
|
||||
|
@ -593,7 +600,9 @@ pub trait FromArgMatches: Sized {
|
|||
fn from_argmatches<'a>(matches: &::parse::ArgMatches<'a>) -> Self;
|
||||
|
||||
/// @TODO @release @docs
|
||||
fn try_from_argmatches<'a>(matches: &::parse::ArgMatches<'a>) -> StdResult<Self, ::parse::errors::Error> {
|
||||
fn try_from_argmatches<'a>(
|
||||
matches: &::parse::ArgMatches<'a>,
|
||||
) -> StdResult<Self, ::parse::errors::Error> {
|
||||
Ok(<Self as FromArgMatches>::from_argmatches(matches))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -727,7 +727,7 @@ macro_rules! clap_app {
|
|||
clap_app!{ @arg ($arg.long(stringify!($long))) $modes $($tail)* }
|
||||
};
|
||||
(@arg ($arg:expr) $modes:tt -$short:ident $($tail:tt)*) => {
|
||||
clap_app!{ @arg ($arg.short(stringify!($short))) $modes $($tail)* }
|
||||
clap_app!{ @arg ($arg.short(stringify!($short).chars().nth(0).unwrap())) $modes $($tail)* }
|
||||
};
|
||||
(@arg ($arg:expr) (-) <$var:ident> $($tail:tt)*) => {
|
||||
clap_app!{ @arg ($arg.value_name(stringify!($var))) (+) +takes_value +required $($tail)* }
|
||||
|
|
|
@ -309,7 +309,7 @@ pub enum ErrorKind {
|
|||
/// let result = App::new("prog")
|
||||
/// .setting(AppSettings::StrictUtf8)
|
||||
/// .arg(Arg::with_name("utf8")
|
||||
/// .short("u")
|
||||
/// .short('u')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from_safe(vec![OsString::from("myprog"),
|
||||
/// OsString::from("-u"),
|
||||
|
|
|
@ -25,10 +25,10 @@ use parse::{MatchedArg, SubCommand};
|
|||
/// .required(true)
|
||||
/// .takes_value(true))
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .multiple(true))
|
||||
/// .arg(Arg::with_name("cfg")
|
||||
/// .short("c")
|
||||
/// .short('c')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches(); // builds the instance of ArgMatches
|
||||
///
|
||||
|
@ -202,7 +202,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("output")
|
||||
/// .multiple(true)
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from(vec![
|
||||
/// "myprog", "-o", "val1", "val2", "val3"
|
||||
|
@ -309,7 +309,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d"))
|
||||
/// .short('d'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "myprog", "-d"
|
||||
/// ]);
|
||||
|
@ -338,7 +338,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .setting(ArgSettings::MultipleOccurrences))
|
||||
/// .get_matches_from(vec![
|
||||
/// "myprog", "-d", "-d", "-d"
|
||||
|
@ -353,10 +353,10 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg, ArgSettings};
|
||||
/// let m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d")
|
||||
/// .short('d')
|
||||
/// .setting(ArgSettings::MultipleOccurrences))
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .get_matches_from(vec![
|
||||
/// "myprog", "-ddfd"
|
||||
/// ]);
|
||||
|
@ -395,9 +395,9 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from(vec!["myapp", "-f", "-o", "val"]);
|
||||
/// // ARGV idices: ^0 ^1 ^2 ^3
|
||||
|
@ -413,9 +413,9 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from(vec!["myapp", "-f", "-o=val"]);
|
||||
/// // ARGV idices: ^0 ^1 ^2
|
||||
|
@ -432,13 +432,13 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("flag2")
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .arg(Arg::with_name("flag3")
|
||||
/// .short("z"))
|
||||
/// .short('z'))
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from(vec!["myapp", "-fzF", "-oval"]);
|
||||
/// // ARGV idices: ^0 ^1 ^2
|
||||
|
@ -458,13 +458,13 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f"))
|
||||
/// .short('f'))
|
||||
/// .arg(Arg::with_name("flag2")
|
||||
/// .short("F"))
|
||||
/// .short('F'))
|
||||
/// .arg(Arg::with_name("flag3")
|
||||
/// .short("z"))
|
||||
/// .short('z'))
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true)
|
||||
/// .multiple(true))
|
||||
/// .get_matches_from(vec!["myapp", "-fzFoval"]);
|
||||
|
@ -485,7 +485,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true)
|
||||
/// .multiple(true))
|
||||
/// .get_matches_from(vec!["myapp", "-o=val1,val2,val3"]);
|
||||
|
@ -524,7 +524,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true)
|
||||
/// .use_delimiter(true)
|
||||
/// .multiple(true))
|
||||
|
@ -543,11 +543,11 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true)
|
||||
/// .multiple(true))
|
||||
/// .arg(Arg::with_name("flag")
|
||||
/// .short("f")
|
||||
/// .short('f')
|
||||
/// .multiple_occurrences(true))
|
||||
/// .get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
|
||||
/// // ARGV idices: ^0 ^1 ^2 ^3 ^4 ^5 ^6
|
||||
|
@ -566,7 +566,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("option")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .takes_value(true)
|
||||
/// .multiple(true))
|
||||
/// .get_matches_from(vec!["myapp", "-o=val1,val2,val3"]);
|
||||
|
@ -601,7 +601,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg, SubCommand};
|
||||
/// let app_m = App::new("myprog")
|
||||
/// .arg(Arg::with_name("debug")
|
||||
/// .short("d"))
|
||||
/// .short('d'))
|
||||
/// .subcommand(SubCommand::with_name("test")
|
||||
/// .arg(Arg::with_name("opt")
|
||||
/// .long("option")
|
||||
|
@ -777,7 +777,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("output")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .multiple(true)
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from(vec!["myapp", "-o", "val1", "val2"]);
|
||||
|
@ -881,7 +881,7 @@ impl<'a> Default for OsValues<'a> {
|
|||
/// # use clap::{App, Arg};
|
||||
/// let m = App::new("myapp")
|
||||
/// .arg(Arg::with_name("output")
|
||||
/// .short("o")
|
||||
/// .short('o')
|
||||
/// .multiple(true)
|
||||
/// .takes_value(true))
|
||||
/// .get_matches_from(vec!["myapp", "-o", "val1", "val2"]);
|
||||
|
|
|
@ -421,7 +421,7 @@ fn leading_hyphen_short() {
|
|||
let res = App::new("leadhy")
|
||||
.setting(AppSettings::AllowLeadingHyphen)
|
||||
.arg(Arg::with_name("some"))
|
||||
.arg(Arg::with_name("other").short("o"))
|
||||
.arg(Arg::with_name("other").short('o'))
|
||||
.get_matches_from_safe(vec!["", "-bar", "-o"]);
|
||||
assert!(res.is_ok(), "Error: {:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
|
@ -435,7 +435,7 @@ fn leading_hyphen_long() {
|
|||
let res = App::new("leadhy")
|
||||
.setting(AppSettings::AllowLeadingHyphen)
|
||||
.arg(Arg::with_name("some"))
|
||||
.arg(Arg::with_name("other").short("o"))
|
||||
.arg(Arg::with_name("other").short('o'))
|
||||
.get_matches_from_safe(vec!["", "--bar", "-o"]);
|
||||
assert!(res.is_ok(), "Error: {:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
|
@ -449,7 +449,7 @@ fn leading_hyphen_opt() {
|
|||
let res = App::new("leadhy")
|
||||
.setting(AppSettings::AllowLeadingHyphen)
|
||||
.arg(Arg::with_name("some").takes_value(true).long("opt"))
|
||||
.arg(Arg::with_name("other").short("o"))
|
||||
.arg(Arg::with_name("other").short('o'))
|
||||
.get_matches_from_safe(vec!["", "--opt", "--bar", "-o"]);
|
||||
assert!(res.is_ok(), "Error: {:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
|
@ -463,7 +463,7 @@ fn allow_negative_numbers() {
|
|||
let res = App::new("negnum")
|
||||
.setting(AppSettings::AllowNegativeNumbers)
|
||||
.arg(Arg::with_name("panum"))
|
||||
.arg(Arg::with_name("onum").short("o").takes_value(true))
|
||||
.arg(Arg::with_name("onum").short('o').takes_value(true))
|
||||
.get_matches_from_safe(vec!["negnum", "-20", "-o", "-1.2"]);
|
||||
assert!(res.is_ok(), "Error: {:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
|
@ -476,7 +476,7 @@ fn allow_negative_numbers_fail() {
|
|||
let res = App::new("negnum")
|
||||
.setting(AppSettings::AllowNegativeNumbers)
|
||||
.arg(Arg::with_name("panum"))
|
||||
.arg(Arg::with_name("onum").short("o").takes_value(true))
|
||||
.arg(Arg::with_name("onum").short('o').takes_value(true))
|
||||
.get_matches_from_safe(vec!["negnum", "--foo", "-o", "-1.2"]);
|
||||
assert!(res.is_err());
|
||||
assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument)
|
||||
|
@ -551,7 +551,7 @@ fn require_eq() {
|
|||
let app = App::new("clap-test").version("v1.4.8").arg(
|
||||
Arg::with_name("opt")
|
||||
.long("opt")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.required(true)
|
||||
.require_equals(true)
|
||||
.value_name("FILE")
|
||||
|
|
|
@ -137,7 +137,7 @@ fn alias_on_a_subcommand_option() {
|
|||
.subcommand(
|
||||
SubCommand::with_name("some").arg(
|
||||
Arg::with_name("test")
|
||||
.short("t")
|
||||
.short('t')
|
||||
.long("test")
|
||||
.takes_value(true)
|
||||
.alias("opt")
|
||||
|
@ -166,7 +166,7 @@ fn invisible_arg_aliases_help_output() {
|
|||
.arg(
|
||||
Arg::with_name("opt")
|
||||
.long("opt")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true)
|
||||
.aliases(&["invisible", "als1", "more"]),
|
||||
)
|
||||
|
@ -189,7 +189,7 @@ fn visible_arg_aliases_help_output() {
|
|||
.arg(
|
||||
Arg::with_name("opt")
|
||||
.long("opt")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true)
|
||||
.alias("invisible")
|
||||
.visible_alias("visible"),
|
||||
|
@ -197,7 +197,7 @@ fn visible_arg_aliases_help_output() {
|
|||
.arg(
|
||||
Arg::with_name("flg")
|
||||
.long("flag")
|
||||
.short("f")
|
||||
.short('f')
|
||||
.visible_aliases(&["v_flg", "flag2", "flg3"]),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -8,11 +8,11 @@ include!("../clap-test.rs");
|
|||
#[test]
|
||||
fn borrowed_args() {
|
||||
let arg = Arg::with_name("some")
|
||||
.short("s")
|
||||
.short('s')
|
||||
.long("some")
|
||||
.help("other help");
|
||||
let arg2 = Arg::with_name("some2")
|
||||
.short("S")
|
||||
.short('S')
|
||||
.long("some-thing")
|
||||
.help("other help");
|
||||
let result = App::new("sub_command_negate")
|
||||
|
|
|
@ -43,7 +43,7 @@ fn opt_s_eq_no_delim() {
|
|||
let m = App::new("no_delim")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.setting(ArgSettings::TakesValue),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "-o=val1,val2,val3"]);
|
||||
|
@ -61,7 +61,7 @@ fn opt_s_default_no_delim() {
|
|||
let m = App::new("no_delim")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.setting(ArgSettings::TakesValue),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "-o", "val1,val2,val3"]);
|
||||
|
@ -79,7 +79,7 @@ fn opt_s_no_space_no_delim() {
|
|||
let m = App::new("no_delim")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.setting(ArgSettings::TakesValue),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "-o", "val1,val2,val3"]);
|
||||
|
@ -97,7 +97,7 @@ fn opt_s_no_space_mult_no_delim() {
|
|||
let m = App::new("no_delim")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.setting(ArgSettings::MultipleValues),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "-o", "val1,val2,val3"]);
|
||||
|
|
|
@ -244,15 +244,15 @@ fn validator() {
|
|||
fn validator_output() {
|
||||
env::set_var("CLP_TEST_ENV", "42");
|
||||
|
||||
let r = App::new("df")
|
||||
let m = App::new("df")
|
||||
.arg(
|
||||
Arg::from("[arg] 'some opt'")
|
||||
.env("CLP_TEST_ENV")
|
||||
.validator(|s| s.parse::<i32>())
|
||||
.validator(|s| s.parse::<i32>()),
|
||||
)
|
||||
.get_matches_from_safe(vec![""]);
|
||||
.get_matches_from(vec![""]);
|
||||
|
||||
assert_eq!(r.unwrap().value_of("arg").unwrap().parse(), Ok(42));
|
||||
assert_eq!(m.value_of("arg").unwrap().parse(), Ok(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
107
tests/help.rs
107
tests/help.rs
|
@ -600,21 +600,21 @@ fn args_with_last_usage() {
|
|||
.arg(
|
||||
Arg::with_name("verbose")
|
||||
.help("Prints out more stuff.")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.long("verbose")
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("timeout")
|
||||
.help("Timeout in seconds.")
|
||||
.short("t")
|
||||
.short('t')
|
||||
.long("timeout")
|
||||
.value_name("SECONDS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("frequency")
|
||||
.help("The sampling frequency.")
|
||||
.short("f")
|
||||
.short('f')
|
||||
.long("frequency")
|
||||
.value_name("HERTZ"),
|
||||
)
|
||||
|
@ -749,7 +749,7 @@ fn complex_subcommand_help_output() {
|
|||
fn issue_626_unicode_cutoff() {
|
||||
let app = App::new("ctest").version("0.1").set_term_width(70).arg(
|
||||
Arg::with_name("cafe")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.help(
|
||||
|
@ -776,7 +776,7 @@ fn hide_possible_vals() {
|
|||
.version("0.1")
|
||||
.arg(
|
||||
Arg::with_name("pos")
|
||||
.short("p")
|
||||
.short('p')
|
||||
.long("pos")
|
||||
.value_name("VAL")
|
||||
.possible_values(&["fast", "slow"])
|
||||
|
@ -785,7 +785,7 @@ fn hide_possible_vals() {
|
|||
)
|
||||
.arg(
|
||||
Arg::with_name("cafe")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_possible_values(true)
|
||||
|
@ -807,7 +807,7 @@ fn issue_626_panic() {
|
|||
.version("0.1")
|
||||
.set_term_width(52)
|
||||
.arg(Arg::with_name("cafe")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \
|
||||
|
@ -829,7 +829,7 @@ fn issue_626_variable_panic() {
|
|||
.version("0.1")
|
||||
.set_term_width(i)
|
||||
.arg(Arg::with_name("cafe")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \
|
||||
|
@ -853,13 +853,14 @@ fn final_word_wrapping() {
|
|||
|
||||
#[test]
|
||||
fn wrapping_newline_chars() {
|
||||
let app = App::new("ctest").version("0.1").set_term_width(60).arg(
|
||||
Arg::with_name("mode").help(
|
||||
let app = App::new("ctest")
|
||||
.version("0.1")
|
||||
.set_term_width(60)
|
||||
.arg(Arg::with_name("mode").help(
|
||||
"x, max, maximum 20 characters, contains symbols.{n}\
|
||||
l, long Copy-friendly, 14 characters, contains symbols.{n}\
|
||||
m, med, medium Copy-friendly, 8 characters, contains symbols.{n}",
|
||||
),
|
||||
);
|
||||
));
|
||||
assert!(test::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
|
@ -872,7 +873,7 @@ fn wrapping_newline_chars() {
|
|||
fn old_newline_chars() {
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::with_name("mode")
|
||||
.short("m")
|
||||
.short('m')
|
||||
.help("Some help with some wrapping{n}(Defaults to something)"),
|
||||
);
|
||||
assert!(test::compare_output(
|
||||
|
@ -932,21 +933,21 @@ fn issue_702_multiple_values() {
|
|||
.arg(
|
||||
Arg::with_name("some")
|
||||
.help("some option")
|
||||
.short("s")
|
||||
.short('s')
|
||||
.long("some")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("other")
|
||||
.help("some other option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.long("other")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("label")
|
||||
.help("a label")
|
||||
.short("l")
|
||||
.short('l')
|
||||
.long("label")
|
||||
.multiple(true)
|
||||
.takes_value(true),
|
||||
|
@ -974,7 +975,7 @@ fn issue_760() {
|
|||
.arg(
|
||||
Arg::with_name("option")
|
||||
.help("tests options")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.long("option")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -983,7 +984,7 @@ fn issue_760() {
|
|||
.arg(
|
||||
Arg::with_name("opt")
|
||||
.help("tests options")
|
||||
.short("O")
|
||||
.short('O')
|
||||
.long("opt")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
@ -1305,7 +1306,7 @@ fn hide_env_vals() {
|
|||
.version("0.1")
|
||||
.arg(
|
||||
Arg::with_name("pos")
|
||||
.short("p")
|
||||
.short('p')
|
||||
.long("pos")
|
||||
.value_name("VAL")
|
||||
.possible_values(&["fast", "slow"])
|
||||
|
@ -1314,7 +1315,7 @@ fn hide_env_vals() {
|
|||
)
|
||||
.arg(
|
||||
Arg::with_name("cafe")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_env_values(true)
|
||||
|
@ -1339,7 +1340,7 @@ fn show_env_vals() {
|
|||
.version("0.1")
|
||||
.arg(
|
||||
Arg::with_name("pos")
|
||||
.short("p")
|
||||
.short('p')
|
||||
.long("pos")
|
||||
.value_name("VAL")
|
||||
.possible_values(&["fast", "slow"])
|
||||
|
@ -1348,7 +1349,7 @@ fn show_env_vals() {
|
|||
)
|
||||
.arg(
|
||||
Arg::with_name("cafe")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_possible_values(true)
|
||||
|
@ -1370,15 +1371,17 @@ fn custom_headers_headers() {
|
|||
.author("Will M.")
|
||||
.about("does stuff")
|
||||
.version("1.4")
|
||||
.arg(Arg::from("-f, --fake <some> <val> 'some help'")
|
||||
.arg(
|
||||
Arg::from("-f, --fake <some> <val> 'some help'")
|
||||
.require_delimiter(true)
|
||||
.value_delimiter(":"),
|
||||
)
|
||||
.help_heading("NETWORKING")
|
||||
.arg(Arg::with_name("no-proxy")
|
||||
.short("n")
|
||||
.arg(
|
||||
Arg::with_name("no-proxy")
|
||||
.short('n')
|
||||
.long("no-proxy")
|
||||
.help("Do not use system proxy settings")
|
||||
.help("Do not use system proxy settings"),
|
||||
);
|
||||
|
||||
assert!(test::compare_output(
|
||||
|
@ -1416,26 +1419,32 @@ fn multiple_custom_help_headers() {
|
|||
.author("Will M.")
|
||||
.about("does stuff")
|
||||
.version("1.4")
|
||||
.arg(Arg::from("-f, --fake <some> <val> 'some help'")
|
||||
.arg(
|
||||
Arg::from("-f, --fake <some> <val> 'some help'")
|
||||
.require_delimiter(true)
|
||||
.value_delimiter(":"),
|
||||
)
|
||||
.help_heading("NETWORKING")
|
||||
.arg(Arg::with_name("no-proxy")
|
||||
.short("n")
|
||||
.arg(
|
||||
Arg::with_name("no-proxy")
|
||||
.short('n')
|
||||
.long("no-proxy")
|
||||
.help("Do not use system proxy settings")
|
||||
.help("Do not use system proxy settings"),
|
||||
)
|
||||
.help_heading("SPECIAL")
|
||||
.arg(Arg::from("-b, --birthday-song <song> 'Change which song is played for birthdays'"))
|
||||
.arg(Arg::from(
|
||||
"-b, --birthday-song <song> 'Change which song is played for birthdays'",
|
||||
))
|
||||
.stop_custom_headings()
|
||||
.arg(Arg::with_name("speed")
|
||||
.arg(
|
||||
Arg::with_name("speed")
|
||||
.long("speed")
|
||||
.short("s")
|
||||
.short('s')
|
||||
.value_name("SPEED")
|
||||
.possible_values(&["fast", "slow"])
|
||||
.help("How fast?")
|
||||
.takes_value(true));
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
assert!(test::compare_output(
|
||||
app,
|
||||
|
@ -1460,13 +1469,18 @@ FLAGS:
|
|||
|
||||
#[test]
|
||||
fn show_long_about_issue_897() {
|
||||
let app = App::new("ctest")
|
||||
.version("0.1")
|
||||
.subcommand(SubCommand::with_name("foo")
|
||||
let app = App::new("ctest").version("0.1").subcommand(
|
||||
SubCommand::with_name("foo")
|
||||
.version("0.1")
|
||||
.about("About foo")
|
||||
.long_about("Long about foo"));
|
||||
assert!(test::compare_output(app, "ctest foo --help", ISSUE_897, false));
|
||||
.long_about("Long about foo"),
|
||||
);
|
||||
assert!(test::compare_output(
|
||||
app,
|
||||
"ctest foo --help",
|
||||
ISSUE_897,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
static ISSUE_897_SHORT: &'static str = "ctest-foo 0.1
|
||||
|
@ -1481,11 +1495,16 @@ FLAGS:
|
|||
|
||||
#[test]
|
||||
fn show_short_about_issue_897() {
|
||||
let app = App::new("ctest")
|
||||
.version("0.1")
|
||||
.subcommand(SubCommand::with_name("foo")
|
||||
let app = App::new("ctest").version("0.1").subcommand(
|
||||
SubCommand::with_name("foo")
|
||||
.version("0.1")
|
||||
.about("About foo")
|
||||
.long_about("Long about foo"));
|
||||
assert!(test::compare_output(app, "ctest foo -h", ISSUE_897_SHORT, false));
|
||||
.long_about("Long about foo"),
|
||||
);
|
||||
assert!(test::compare_output(
|
||||
app,
|
||||
"ctest foo -h",
|
||||
ISSUE_897_SHORT,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
|
|
@ -76,12 +76,12 @@ fn hidden_short_args() {
|
|||
.version("2.31.2")
|
||||
.args(&[
|
||||
Arg::with_name("cfg")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.hidden_short_help(true)
|
||||
.help("Some help text describing the --config arg"),
|
||||
Arg::with_name("visible")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.long("visible")
|
||||
.help("This text should be visible")]);
|
||||
|
||||
|
@ -97,12 +97,12 @@ fn hidden_short_args_long_help() {
|
|||
.version("2.31.2")
|
||||
.args(&[
|
||||
Arg::with_name("cfg")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.hidden_short_help(true)
|
||||
.help("Some help text describing the --config arg"),
|
||||
Arg::with_name("visible")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.long("visible")
|
||||
.help("This text should be visible")]);
|
||||
|
||||
|
@ -134,12 +134,12 @@ fn hidden_long_args() {
|
|||
.version("2.31.2")
|
||||
.args(&[
|
||||
Arg::with_name("cfg")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.hidden_long_help(true)
|
||||
.help("Some help text describing the --config arg"),
|
||||
Arg::with_name("visible")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.long("visible")
|
||||
.help("This text should be visible")]);
|
||||
|
||||
|
@ -167,12 +167,12 @@ fn hidden_long_args_short_help() {
|
|||
.version("2.31.2")
|
||||
.args(&[
|
||||
Arg::with_name("cfg")
|
||||
.short("c")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.hidden_long_help(true)
|
||||
.help("Some help text describing the --config arg"),
|
||||
Arg::with_name("visible")
|
||||
.short("v")
|
||||
.short('v')
|
||||
.long("visible")
|
||||
.help("This text should be visible")]);
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ use clap::{App, Arg};
|
|||
fn indices_mult_opts() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
.get_matches_from(vec!["ind", "-e", "A", "B", "-i", "B", "C", "-e", "C"]);
|
||||
|
@ -26,11 +26,11 @@ fn indices_mult_opts() {
|
|||
fn index_mult_opts() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
.get_matches_from(vec!["ind", "-e", "A", "B", "-i", "B", "C", "-e", "C"]);
|
||||
|
@ -43,9 +43,9 @@ fn index_mult_opts() {
|
|||
fn index_flag() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e"))
|
||||
.short('e'))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i"))
|
||||
.short('i'))
|
||||
.get_matches_from(vec!["ind", "-e", "-i"]);
|
||||
|
||||
assert_eq!(m.index_of("exclude"), Some(1));
|
||||
|
@ -56,10 +56,10 @@ fn index_flag() {
|
|||
fn index_flags() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.multiple_occurrences(true))
|
||||
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
|
||||
|
||||
|
@ -71,10 +71,10 @@ fn index_flags() {
|
|||
fn indices_mult_flags() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.multiple_occurrences(true))
|
||||
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
|
||||
|
||||
|
@ -86,10 +86,10 @@ fn indices_mult_flags() {
|
|||
fn indices_mult_flags_combined() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.multiple_occurrences(true))
|
||||
.get_matches_from(vec!["ind", "-eieei"]);
|
||||
|
||||
|
@ -101,13 +101,13 @@ fn indices_mult_flags_combined() {
|
|||
fn indices_mult_flags_opt_combined() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true))
|
||||
.get_matches_from(vec!["ind", "-eieeio", "val"]);
|
||||
|
||||
|
@ -120,13 +120,13 @@ fn indices_mult_flags_opt_combined() {
|
|||
fn indices_mult_flags_opt_combined_eq() {
|
||||
let m = App::new("ind")
|
||||
.arg(Arg::with_name("exclude")
|
||||
.short("e")
|
||||
.short('e')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("include")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true))
|
||||
.get_matches_from(vec!["ind", "-eieeio=val"]);
|
||||
|
||||
|
@ -139,7 +139,7 @@ fn indices_mult_flags_opt_combined_eq() {
|
|||
fn indices_mult_opt_value_delim_eq() {
|
||||
let m = App::new("myapp")
|
||||
.arg(Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true)
|
||||
.use_delimiter(true)
|
||||
.multiple(true))
|
||||
|
@ -151,7 +151,7 @@ fn indices_mult_opt_value_delim_eq() {
|
|||
fn indices_mult_opt_value_no_delim_eq() {
|
||||
let m = App::new("myapp")
|
||||
.arg(Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
.get_matches_from(vec!["myapp", "-o=val1,val2,val3"]);
|
||||
|
@ -162,11 +162,11 @@ fn indices_mult_opt_value_no_delim_eq() {
|
|||
fn indices_mult_opt_mult_flag() {
|
||||
let m = App::new("myapp")
|
||||
.arg(Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.takes_value(true)
|
||||
.multiple_occurrences(true))
|
||||
.arg(Arg::with_name("flag")
|
||||
.short("f")
|
||||
.short('f')
|
||||
.multiple_occurrences(true))
|
||||
.get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ fn option_long() {
|
|||
.multiple(true),
|
||||
)
|
||||
.get_matches_from_safe(vec![
|
||||
"", "--option", "val1", "--option", "val2", "--option", "val3"
|
||||
"", "--option", "val1", "--option", "val2", "--option", "val3",
|
||||
]);
|
||||
|
||||
assert!(m.is_ok());
|
||||
|
@ -32,7 +32,7 @@ fn option_short() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true),
|
||||
|
@ -56,13 +56,13 @@ fn option_mixed() {
|
|||
.arg(
|
||||
Arg::with_name("option")
|
||||
.long("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true),
|
||||
)
|
||||
.get_matches_from_safe(vec![
|
||||
"", "-o", "val1", "--option", "val2", "--option", "val3", "-o", "val4"
|
||||
"", "-o", "val1", "--option", "val2", "--option", "val3", "-o", "val4",
|
||||
]);
|
||||
|
||||
assert!(m.is_ok());
|
||||
|
@ -81,7 +81,7 @@ fn option_exact_exact() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -105,7 +105,7 @@ fn option_exact_exact_not_mult() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.number_of_values(3),
|
||||
|
@ -128,14 +128,14 @@ fn option_exact_exact_mult() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.number_of_values(3),
|
||||
)
|
||||
.get_matches_from_safe(vec![
|
||||
"", "-o", "val1", "val2", "val3", "-o", "val4", "val5", "val6"
|
||||
"", "-o", "val1", "val2", "val3", "-o", "val4", "val5", "val6",
|
||||
]);
|
||||
|
||||
assert!(m.is_ok());
|
||||
|
@ -154,7 +154,7 @@ fn option_exact_less() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -171,14 +171,14 @@ fn option_exact_more() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.number_of_values(3),
|
||||
)
|
||||
.get_matches_from_safe(vec![
|
||||
"", "-o", "val1", "-o", "val2", "-o", "val3", "-o", "val4"
|
||||
"", "-o", "val1", "-o", "val2", "-o", "val3", "-o", "val4",
|
||||
]);
|
||||
|
||||
assert!(m.is_err());
|
||||
|
@ -190,7 +190,7 @@ fn option_min_exact() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -214,7 +214,7 @@ fn option_min_less() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -232,14 +232,14 @@ fn option_short_min_more_mult_occurs() {
|
|||
.arg(Arg::with_name("arg").required(true))
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.min_values(3),
|
||||
)
|
||||
.get_matches_from_safe(vec![
|
||||
"", "pos", "-o", "val1", "-o", "val2", "-o", "val3", "-o", "val4"
|
||||
"", "pos", "-o", "val1", "-o", "val2", "-o", "val3", "-o", "val4",
|
||||
]);
|
||||
|
||||
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind);
|
||||
|
@ -261,7 +261,7 @@ fn option_short_min_more_single_occur() {
|
|||
.arg(Arg::with_name("arg").required(true))
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -287,7 +287,7 @@ fn option_max_exact() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -311,7 +311,7 @@ fn option_max_less() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
|
@ -335,14 +335,14 @@ fn option_max_more() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.max_values(3),
|
||||
)
|
||||
.get_matches_from_safe(vec![
|
||||
"", "-o", "val1", "-o", "val2", "-o", "val3", "-o", "val4"
|
||||
"", "-o", "val1", "-o", "val2", "-o", "val3", "-o", "val4",
|
||||
]);
|
||||
|
||||
assert!(m.is_err());
|
||||
|
@ -584,7 +584,7 @@ fn sep_short_equals() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.use_delimiter(true)
|
||||
.takes_value(true)
|
||||
|
@ -608,7 +608,7 @@ fn sep_short_space() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.use_delimiter(true)
|
||||
.takes_value(true)
|
||||
|
@ -632,7 +632,7 @@ fn sep_short_no_space() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("multiple options")
|
||||
.use_delimiter(true)
|
||||
.takes_value(true)
|
||||
|
@ -818,7 +818,7 @@ fn req_delimiter_short_with_space() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.multiple(true)
|
||||
.use_delimiter(true)
|
||||
.require_delimiter(true)
|
||||
|
@ -847,7 +847,7 @@ fn req_delimiter_short_with_no_space() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.multiple(true)
|
||||
.use_delimiter(true)
|
||||
.require_delimiter(true)
|
||||
|
@ -876,7 +876,7 @@ fn req_delimiter_short_with_equal() {
|
|||
let m = App::new("multiple_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("option")
|
||||
.short('o')
|
||||
.multiple(true)
|
||||
.use_delimiter(true)
|
||||
.require_delimiter(true)
|
||||
|
@ -906,7 +906,7 @@ fn req_delimiter_complex() {
|
|||
.arg(
|
||||
Arg::with_name("option")
|
||||
.long("option")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.multiple(true)
|
||||
.use_delimiter(true)
|
||||
.require_delimiter(true)
|
||||
|
@ -1079,7 +1079,7 @@ fn low_index_positional_with_option() {
|
|||
.arg(Arg::with_name("target").index(2).required(true))
|
||||
.arg(Arg::with_name("opt").long("option").takes_value(true))
|
||||
.get_matches_from_safe(vec![
|
||||
"lip", "file1", "file2", "file3", "target", "--option", "test"
|
||||
"lip", "file1", "file2", "file3", "target", "--option", "test",
|
||||
]);
|
||||
|
||||
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
|
||||
|
@ -1130,7 +1130,7 @@ fn multiple_value_terminator_option() {
|
|||
let m = App::new("lip")
|
||||
.arg(
|
||||
Arg::with_name("files")
|
||||
.short("f")
|
||||
.short('f')
|
||||
.value_terminator(";")
|
||||
.multiple(true),
|
||||
)
|
||||
|
@ -1155,12 +1155,12 @@ fn multiple_value_terminator_option_other_arg() {
|
|||
let m = App::new("lip")
|
||||
.arg(
|
||||
Arg::with_name("files")
|
||||
.short("f")
|
||||
.short('f')
|
||||
.value_terminator(";")
|
||||
.multiple(true),
|
||||
)
|
||||
.arg(Arg::with_name("other"))
|
||||
.arg(Arg::with_name("flag").short("-F"))
|
||||
.arg(Arg::with_name("flag").short('F'))
|
||||
.get_matches_from_safe(vec!["lip", "-f", "val1", "val2", "-F", "otherval"]);
|
||||
|
||||
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
|
||||
|
|
|
@ -385,7 +385,7 @@ fn issue_1047_min_zero_vals_default_val() {
|
|||
let m = App::new("foo")
|
||||
.arg(
|
||||
Arg::with_name("del")
|
||||
.short("d")
|
||||
.short('d')
|
||||
.long("del")
|
||||
.setting(ArgSettings::RequireEquals)
|
||||
.min_values(0)
|
||||
|
|
|
@ -103,7 +103,7 @@ fn possible_values_of_option() {
|
|||
let m = App::new("possible_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123"),
|
||||
|
@ -122,7 +122,7 @@ fn possible_values_of_option_fail() {
|
|||
let m = App::new("possible_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123"),
|
||||
|
@ -138,7 +138,7 @@ fn possible_values_of_option_multiple() {
|
|||
let m = App::new("possible_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123")
|
||||
|
@ -162,7 +162,7 @@ fn possible_values_of_option_multiple_fail() {
|
|||
let m = App::new("possible_values")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123")
|
||||
|
@ -190,7 +190,7 @@ fn case_insensitive() {
|
|||
let m = App::new("pv")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123")
|
||||
|
@ -213,7 +213,7 @@ fn case_insensitive_faili() {
|
|||
let m = App::new("pv")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123")
|
||||
|
@ -230,7 +230,7 @@ fn case_insensitive_multiple() {
|
|||
let m = App::new("pv")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123")
|
||||
|
@ -252,7 +252,7 @@ fn case_insensitive_multiple_fail() {
|
|||
let m = App::new("pv")
|
||||
.arg(
|
||||
Arg::with_name("option")
|
||||
.short("-o")
|
||||
.short('o')
|
||||
.long("--option")
|
||||
.takes_value(true)
|
||||
.possible_value("test123")
|
||||
|
|
|
@ -260,7 +260,7 @@ fn required_unless_all() {
|
|||
.long("config"),
|
||||
)
|
||||
.arg(Arg::with_name("dbg").long("debug"))
|
||||
.arg(Arg::with_name("infile").short("i").takes_value(true))
|
||||
.arg(Arg::with_name("infile").short('i').takes_value(true))
|
||||
.get_matches_from_safe(vec!["unlessall", "--debug", "-i", "file"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
|
@ -280,7 +280,7 @@ fn required_unless_all_err() {
|
|||
.long("config"),
|
||||
)
|
||||
.arg(Arg::with_name("dbg").long("debug"))
|
||||
.arg(Arg::with_name("infile").short("i").takes_value(true))
|
||||
.arg(Arg::with_name("infile").short('i').takes_value(true))
|
||||
.get_matches_from_safe(vec!["unlessall", "--debug"]);
|
||||
|
||||
assert!(res.is_err());
|
||||
|
@ -299,7 +299,7 @@ fn required_unless_one() {
|
|||
.long("config"),
|
||||
)
|
||||
.arg(Arg::with_name("dbg").long("debug"))
|
||||
.arg(Arg::with_name("infile").short("i").takes_value(true))
|
||||
.arg(Arg::with_name("infile").short('i').takes_value(true))
|
||||
.get_matches_from_safe(vec!["unlessone", "--debug"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
|
@ -320,7 +320,7 @@ fn required_unless_one_2() {
|
|||
.long("config"),
|
||||
)
|
||||
.arg(Arg::with_name("dbg").long("debug"))
|
||||
.arg(Arg::with_name("infile").short("i").takes_value(true))
|
||||
.arg(Arg::with_name("infile").short('i').takes_value(true))
|
||||
.get_matches_from_safe(vec!["unlessone", "-i", "file"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
|
@ -333,11 +333,11 @@ fn required_unless_one_2() {
|
|||
fn required_unless_one_works_with_short() {
|
||||
// GitHub issue: https://github.com/kbknapp/clap-rs/issues/1135
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short('a'))
|
||||
.arg(Arg::with_name("b").short('b'))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.short("x")
|
||||
.short('x')
|
||||
.required_unless_one(&["a", "b"]),
|
||||
)
|
||||
.get_matches_from_safe(vec!["unlessone", "-a"]);
|
||||
|
@ -348,11 +348,11 @@ fn required_unless_one_works_with_short() {
|
|||
#[test]
|
||||
fn required_unless_one_works_with_short_err() {
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short('a'))
|
||||
.arg(Arg::with_name("b").short('b'))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.short("x")
|
||||
.short('x')
|
||||
.required_unless_one(&["a", "b"]),
|
||||
)
|
||||
.get_matches_from_safe(vec!["unlessone"]);
|
||||
|
@ -363,8 +363,8 @@ fn required_unless_one_works_with_short_err() {
|
|||
#[test]
|
||||
fn required_unless_one_works_without() {
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short('a'))
|
||||
.arg(Arg::with_name("b").short('b'))
|
||||
.arg(Arg::with_name("x").required_unless_one(&["a", "b"]))
|
||||
.get_matches_from_safe(vec!["unlessone", "-a"]);
|
||||
|
||||
|
@ -374,8 +374,8 @@ fn required_unless_one_works_without() {
|
|||
#[test]
|
||||
fn required_unless_one_works_with_long() {
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short('a'))
|
||||
.arg(Arg::with_name("b").short('b'))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.long("x_is_the_option")
|
||||
|
@ -396,7 +396,7 @@ fn required_unless_one_1() {
|
|||
.long("config"),
|
||||
)
|
||||
.arg(Arg::with_name("dbg").long("debug"))
|
||||
.arg(Arg::with_name("infile").short("i").takes_value(true))
|
||||
.arg(Arg::with_name("infile").short('i').takes_value(true))
|
||||
.get_matches_from_safe(vec!["unlessone", "--debug"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
|
@ -416,7 +416,7 @@ fn required_unless_one_err() {
|
|||
.long("config"),
|
||||
)
|
||||
.arg(Arg::with_name("dbg").long("debug"))
|
||||
.arg(Arg::with_name("infile").short("i").takes_value(true))
|
||||
.arg(Arg::with_name("infile").short('i').takes_value(true))
|
||||
.get_matches_from_safe(vec!["unlessone"]);
|
||||
|
||||
assert!(res.is_err());
|
||||
|
@ -654,7 +654,7 @@ fn require_eq() {
|
|||
let app = App::new("clap-test").version("v1.4.8").arg(
|
||||
Arg::with_name("opt")
|
||||
.long("opt")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.required(true)
|
||||
.require_equals(true)
|
||||
.value_name("FILE")
|
||||
|
|
|
@ -58,7 +58,7 @@ fn subcommand() {
|
|||
.subcommand(
|
||||
SubCommand::with_name("some").arg(
|
||||
Arg::with_name("test")
|
||||
.short("t")
|
||||
.short('t')
|
||||
.long("test")
|
||||
.takes_value(true)
|
||||
.help("testing testing"),
|
||||
|
@ -79,7 +79,7 @@ fn subcommand_none_given() {
|
|||
.subcommand(
|
||||
SubCommand::with_name("some").arg(
|
||||
Arg::with_name("test")
|
||||
.short("t")
|
||||
.short('t')
|
||||
.long("test")
|
||||
.takes_value(true)
|
||||
.help("testing testing"),
|
||||
|
@ -97,12 +97,12 @@ fn subcommand_multiple() {
|
|||
.subcommands(vec![
|
||||
SubCommand::with_name("some").arg(
|
||||
Arg::with_name("test")
|
||||
.short("t")
|
||||
.short('t')
|
||||
.long("test")
|
||||
.takes_value(true)
|
||||
.help("testing testing"),
|
||||
),
|
||||
SubCommand::with_name("add").arg(Arg::with_name("roster").short("r")),
|
||||
SubCommand::with_name("add").arg(Arg::with_name("roster").short('r')),
|
||||
])
|
||||
.arg(Arg::with_name("other").long("other"))
|
||||
.get_matches_from(vec!["myprog", "some", "--test", "testing"]);
|
||||
|
@ -217,8 +217,8 @@ fn issue_1031_args_with_same_name_no_more_vals() {
|
|||
fn issue_1161_multiple_hyphen_hyphen() {
|
||||
// from example 22
|
||||
let res = App::new("myprog")
|
||||
.arg(Arg::with_name("eff").short("f"))
|
||||
.arg(Arg::with_name("pea").short("p").takes_value(true))
|
||||
.arg(Arg::with_name("eff").short('f'))
|
||||
.arg(Arg::with_name("pea").short('p').takes_value(true))
|
||||
.arg(Arg::with_name("slop").multiple(true).last(true))
|
||||
.get_matches_from_safe(vec!["-f", "-p=bob", "--", "sloppy", "slop", "-a", "--", "subprogram", "position", "args"]);
|
||||
|
||||
|
|
|
@ -305,8 +305,8 @@ fn create_app() {
|
|||
fn add_multiple_arg() {
|
||||
let _ = App::new("test")
|
||||
.args(&[
|
||||
Arg::with_name("test").short("s"),
|
||||
Arg::with_name("test2").short("l"),
|
||||
Arg::with_name("test").short('s'),
|
||||
Arg::with_name("test2").short('l'),
|
||||
])
|
||||
.get_matches_from(vec![""]);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ use clap::{App, Arg};
|
|||
fn unique_arg_names() {
|
||||
let _ = App::new("some")
|
||||
.args(&[
|
||||
Arg::with_name("arg").short("a"),
|
||||
Arg::with_name("arg").short("b"),
|
||||
Arg::with_name("arg").short('a'),
|
||||
Arg::with_name("arg").short('b'),
|
||||
])
|
||||
.get_matches_safe();
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ fn unique_arg_names() {
|
|||
fn unique_arg_shorts() {
|
||||
let _ = App::new("some")
|
||||
.args(&[
|
||||
Arg::with_name("arg1").short("a"),
|
||||
Arg::with_name("arg2").short("a"),
|
||||
Arg::with_name("arg1").short('a'),
|
||||
Arg::with_name("arg2").short('a'),
|
||||
])
|
||||
.get_matches_safe();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue