mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
Auto merge of #571 - gohyda:master, r=kbknapp
Fix: typo and missing color
This commit is contained in:
commit
691ef58dfb
7 changed files with 21 additions and 19 deletions
|
@ -243,7 +243,7 @@ Below are a few of the features which `clap` supports, full descriptions and usa
|
|||
* **Default Values**: Although not specifically provided by `clap` you can achieve this exact functionality from Rust's `Option<&str>.unwrap_or("some default")` method (or `Result<T,String>.unwrap_or(T)` when using typed values)
|
||||
* **Automatic Version from Cargo.toml**: `clap` is fully compatible with Rust's `env!()` macro for automatically setting the version of your application to the version in your Cargo.toml. See [09_auto_version example](examples/09_auto_version.rs) for how to do this (Thanks to [jhelwig](https://github.com/jhelwig) for pointing this out)
|
||||
* **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the [12_typed_values example](examples/12_typed_values.rs). You can also use `clap`s `arg_enum!` macro to create an enum with variants that automatically implement `std::str::FromStr`. See [13a_enum_values_automatic example](examples/13a_enum_values_automatic.rs) for details
|
||||
* **Suggestions**: Suggests corrections when the user enters a typo. For example, if you defined a `--myoption` argument, and the user mistakenly typed `--moyption` (notice `y` and `o` transposed), they would receive a `Did you mean '--myoption' ?` error and exit gracefully. This also works for subcommands and flags. (Thanks to [Byron](https://github.com/Byron) for the implementation) (This feature can optionally be disabled, see 'Optional Dependencies / Features')
|
||||
* **Suggestions**: Suggests corrections when the user enters a typo. For example, if you defined a `--myoption` argument, and the user mistakenly typed `--moyption` (notice `y` and `o` transposed), they would receive a `Did you mean '--myoption'?` error and exit gracefully. This also works for subcommands and flags. (Thanks to [Byron](https://github.com/Byron) for the implementation) (This feature can optionally be disabled, see 'Optional Dependencies / Features')
|
||||
* **Colorized Errors (Non Windows OS only)**: Error message are printed in in colored text (this feature can optionally be disabled, see 'Optional Dependencies / Features').
|
||||
* **Global Arguments**: Arguments can optionally be defined once, and be available to all child subcommands.
|
||||
* **Custom Validations**: You can define a function to use as a validator of argument values. Imagine defining a function to validate IP addresses, or fail parsing upon error. This means your application logic can be solely focused on *using* values.
|
||||
|
@ -519,7 +519,7 @@ features = [ "suggestions", "color" ]
|
|||
```
|
||||
The following is a list of optional `clap` features:
|
||||
|
||||
* **"suggestions"**: Turns on the `Did you mean '--myoption' ?` feature for when users make typos. (builds dependency `strsim`)
|
||||
* **"suggestions"**: Turns on the `Did you mean '--myoption'?` feature for when users make typos. (builds dependency `strsim`)
|
||||
* **"color"**: Turns on colored error messages. This feature only works on non-Windows OSs. (builds dependency `ansi-term` and `libc`)
|
||||
* **"wrap_help"**: Automatically detects terminal width and wraps long help text lines with proper indentation alignment (builds dependency `libc` and 'unicode-width')
|
||||
* **"lints"**: This is **not** included by default and should only be used while developing to run basic lints against changes. This can only be used on Rust nightly. (builds dependency `clippy`)
|
||||
|
|
|
@ -444,6 +444,10 @@ impl Error {
|
|||
A: AnyArg<'a, 'b> + Display,
|
||||
U: Display
|
||||
{
|
||||
let c = fmt::Colorizer {
|
||||
use_stderr: true,
|
||||
when: color
|
||||
};
|
||||
let suffix =
|
||||
suggestions::did_you_mean_suffix(bad_val.as_ref(),
|
||||
good_vals.iter(),
|
||||
|
@ -451,17 +455,14 @@ impl Error {
|
|||
|
||||
let mut sorted = vec![];
|
||||
for v in good_vals {
|
||||
sorted.push(v.as_ref());
|
||||
let val = format!("{}", c.good(v));
|
||||
sorted.push(val);
|
||||
}
|
||||
sorted.sort();
|
||||
let valid_values = sorted.join(" ");
|
||||
let c = fmt::Colorizer {
|
||||
use_stderr: true,
|
||||
when: color
|
||||
};
|
||||
let valid_values = sorted.join(", ");
|
||||
Error {
|
||||
message: format!("{} '{}' isn't a valid value for '{}'\n\t\
|
||||
[values:{}]\n\
|
||||
[values: {}]\n\
|
||||
{}\n\n\
|
||||
{}\n\n\
|
||||
For more information try {}",
|
||||
|
@ -491,7 +492,7 @@ impl Error {
|
|||
};
|
||||
Error {
|
||||
message: format!("{} The subcommand '{}' wasn't recognized\n\t\
|
||||
Did you mean '{}' ?\n\n\
|
||||
Did you mean '{}'?\n\n\
|
||||
If you believe you received this message in error, try \
|
||||
re-running with '{} {} {}'\n\n\
|
||||
{}\n\n\
|
||||
|
@ -521,11 +522,12 @@ impl Error {
|
|||
};
|
||||
Error {
|
||||
message: format!("{} The subcommand '{}' wasn't recognized\n\n\
|
||||
USAGE:\n\t\
|
||||
{}\n\t\
|
||||
{} help <subcommands>...\n\n\
|
||||
For more information try {}",
|
||||
c.error("error:"),
|
||||
c.warning(&*s),
|
||||
c.warning("USAGE:"),
|
||||
name,
|
||||
c.good("--help")),
|
||||
kind: ErrorKind::UnrecognizedSubcommand,
|
||||
|
|
|
@ -342,7 +342,7 @@
|
|||
//!
|
||||
//! The following is a list of optional `clap` features:
|
||||
//!
|
||||
//! * **"suggestions"**: Turns on the `Did you mean '--myoption' ?` feature for when users make typos.
|
||||
//! * **"suggestions"**: Turns on the `Did you mean '--myoption'?` feature for when users make typos.
|
||||
//! * **"color"**: Turns on colored error messages. This feature only works on non-Windows OSs.
|
||||
//! * **"lints"**: This is **not** included by default and should only be used while developing to run basic lints against changes. This can only be used on Rust nightly.
|
||||
//! * **"debug"**: This is **not** included by default and should only be used while developing to display debugging information.
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn did_you_mean_suffix<'z, T, I>(arg: &str,
|
|||
if let DidYouMeanMessageStyle::EnumValue = style {
|
||||
suffix.push('\'');
|
||||
}
|
||||
suffix.push_str(" ?");
|
||||
suffix.push_str("?");
|
||||
(suffix, Some(candidate))
|
||||
}
|
||||
None => (String::new(), None),
|
||||
|
@ -92,7 +92,7 @@ mod test {
|
|||
#[test]
|
||||
fn suffix_long() {
|
||||
let p_vals = ["test", "possible", "values"];
|
||||
let suffix = "\n\tDid you mean \'--test\' ?";
|
||||
let suffix = "\n\tDid you mean \'--test\'?";
|
||||
assert_eq!(did_you_mean_suffix("tst", p_vals.iter(), DidYouMeanMessageStyle::LongFlag),
|
||||
(suffix, Some("test")));
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ mod test {
|
|||
#[test]
|
||||
fn suffix_enum() {
|
||||
let p_vals = ["test", "possible", "values"];
|
||||
let suffix = "\n\tDid you mean \'test\' ?";
|
||||
let suffix = "\n\tDid you mean \'test\'?";
|
||||
assert_eq!(did_you_mean_suffix("tst", p_vals.iter(), DidYouMeanMessageStyle::EnumValue),
|
||||
(suffix, Some("test")));
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ fn require_delims() {
|
|||
fn did_you_mean() {
|
||||
test::check_err_output(test::complex_app(), "clap-test --optio=foo",
|
||||
"error: Found argument '--optio' which wasn't expected, or isn't valid in this context
|
||||
\tDid you mean --option ?
|
||||
\tDid you mean --option?
|
||||
|
||||
USAGE:
|
||||
clap-test --option <opt>...
|
||||
|
|
|
@ -6,9 +6,9 @@ include!("../clap-test.rs");
|
|||
use clap::{App, Arg, ErrorKind};
|
||||
|
||||
static PV_ERROR: &'static str = "error: 'slo' isn't a valid value for '--Option <option3>'
|
||||
\t[values:fast slow]
|
||||
\t[values: fast, slow]
|
||||
|
||||
\tDid you mean 'slow' ?
|
||||
\tDid you mean 'slow'?
|
||||
|
||||
USAGE:
|
||||
clap-test --Option <option3>
|
||||
|
|
|
@ -110,7 +110,7 @@ fn multiple_aliases() {
|
|||
fn subcmd_did_you_mean_output() {
|
||||
test::check_err_output(test::complex_app(), "clap-test subcm",
|
||||
"error: The subcommand 'subcm' wasn't recognized
|
||||
\tDid you mean 'subcmd' ?
|
||||
\tDid you mean 'subcmd'?
|
||||
|
||||
If you believe you received this message in error, try re-running with 'clap-test -- subcm'
|
||||
|
||||
|
|
Loading…
Reference in a new issue