From 8d7bea823fd537c0d718839b546135248e60e602 Mon Sep 17 00:00:00 2001 From: Bence Szigeti Date: Tue, 5 Jul 2016 22:01:04 +0200 Subject: [PATCH 1/3] Fix: extra space typo removed --- README.md | 4 ++-- src/errors.rs | 2 +- src/lib.rs | 2 +- src/suggestions.rs | 6 +++--- tests/opts.rs | 2 +- tests/possible_values.rs | 2 +- tests/subcommands.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9b788108..a6536153 100644 --- a/README.md +++ b/README.md @@ -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.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`) diff --git a/src/errors.rs b/src/errors.rs index 9ef18e98..07c97617 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -491,7 +491,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\ diff --git a/src/lib.rs b/src/lib.rs index e975c12d..e7df31cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. diff --git a/src/suggestions.rs b/src/suggestions.rs index 101b8b0b..8bdd3465 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -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"))); } diff --git a/tests/opts.rs b/tests/opts.rs index a2c58dd4..315d31c9 100644 --- a/tests/opts.rs +++ b/tests/opts.rs @@ -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 ... diff --git a/tests/possible_values.rs b/tests/possible_values.rs index 3c0d4be9..7717bff6 100644 --- a/tests/possible_values.rs +++ b/tests/possible_values.rs @@ -8,7 +8,7 @@ use clap::{App, Arg, ErrorKind}; static PV_ERROR: &'static str = "error: 'slo' isn't a valid value for '--Option ' \t[values:fast slow] -\tDid you mean 'slow' ? +\tDid you mean 'slow'? USAGE: clap-test --Option diff --git a/tests/subcommands.rs b/tests/subcommands.rs index 96815524..8ac3e695 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -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' From f8ca3085dab6d53c63b0434b7db0baae7ac0f5f2 Mon Sep 17 00:00:00 2001 From: Bence Szigeti Date: Tue, 5 Jul 2016 22:04:00 +0200 Subject: [PATCH 2/3] Fix: typo -- missing space and commas --- src/errors.rs | 4 ++-- tests/possible_values.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 07c97617..ae65a9e8 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -454,14 +454,14 @@ impl Error { sorted.push(v.as_ref()); } sorted.sort(); - let valid_values = sorted.join(" "); + let valid_values = sorted.join(", "); let c = fmt::Colorizer { use_stderr: true, when: color }; Error { message: format!("{} '{}' isn't a valid value for '{}'\n\t\ - [values:{}]\n\ + [values: {}]\n\ {}\n\n\ {}\n\n\ For more information try {}", diff --git a/tests/possible_values.rs b/tests/possible_values.rs index 7717bff6..f5e1fb88 100644 --- a/tests/possible_values.rs +++ b/tests/possible_values.rs @@ -6,7 +6,7 @@ include!("../clap-test.rs"); use clap::{App, Arg, ErrorKind}; static PV_ERROR: &'static str = "error: 'slo' isn't a valid value for '--Option ' -\t[values:fast slow] +\t[values: fast, slow] \tDid you mean 'slow'? From 8c32b4b63f31607672dee0dc18ebccfa2713b0ec Mon Sep 17 00:00:00 2001 From: Bence Szigeti Date: Tue, 5 Jul 2016 22:25:35 +0200 Subject: [PATCH 3/3] Fix: missing color --- src/errors.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index ae65a9e8..09ffb6f6 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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,14 +455,11 @@ 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 - }; Error { message: format!("{} '{}' isn't a valid value for '{}'\n\t\ [values: {}]\n\ @@ -521,11 +522,12 @@ impl Error { }; Error { message: format!("{} The subcommand '{}' wasn't recognized\n\n\ - USAGE:\n\t\ + {}\n\t\ {} help ...\n\n\ For more information try {}", c.error("error:"), c.warning(&*s), + c.warning("USAGE:"), name, c.good("--help")), kind: ErrorKind::UnrecognizedSubcommand,