Auto merge of #571 - gohyda:master, r=kbknapp

Fix: typo and missing color
This commit is contained in:
Homu 2016-07-14 01:33:19 +09:00
commit 691ef58dfb
7 changed files with 21 additions and 19 deletions

View file

@ -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`)

View file

@ -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,

View file

@ -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.

View file

@ -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")));
}

View file

@ -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>...

View file

@ -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>

View file

@ -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'