Repository: kbknapp/clap-rs (rust)

Issue:
Incorrect suggestions for flag under subcommand
### Rust Version

`rustc 1.19.0 (0ade33941 2017-07-17)`

### Affected Version of clap

version 2.26.0

### Expected Behavior Summary

When a flag is passed for which no suggestions are found, but for which there is a suggested flag under a subcommand, clap suggests invoking the subcommand with the flag. A message might look like:

> error: Found argument '--subcm' which wasn't expected, or isn't valid in this context
>     Did you mean to put '--subcmdarg' after the subcommand 'subcmd'

### Actual Behavior Summary

The suggestion is misformatted -- it puts the input flag in place of the suggested flag and the suggested flag in place of the subcommand.

The test `subcmd_did_you_mean_output` actually exemplifies the issue. It has the output:

> error: Found argument '--subcmdarg' which wasn't expected, or isn't valid in this context
>     Did you mean to put '--subcmdarg' after the subcommand 'subcmdarg'?

The second `subcmdarg` should be `subcmd`.

### Sample Code or Link to Sample Code

[Here.](https://github.com/kbknapp/clap-rs/blob/76869a0d68193093a70dcb63d248a7da91294a16/tests/subcommands.rs#L46)


Pull request:
Fix suggestions for flags under subcommands
Fixes #1018

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kbknapp/clap-rs/1019)
<!-- Reviewable:end -->


Patch:
diff --git a/src/suggestions.rs b/src/suggestions.rs
index bf586def..cd18d4a2 100644
--- a/src/suggestions.rs
+++ b/src/suggestions.rs
@@ -58,9 +58,10 @@ pub fn did_you_mean_flag_suffix<'z, T, I>(arg: &str, longs: I, subcommands: &'z
 
                 if let Some(candidate) = did_you_mean(arg, opts) {
                     let suffix = format!(
-                        "\n\tDid you mean to put '--{}' after the subcommand '{}'?",
-                        Format::Good(arg),
-                        Format::Good(candidate));
+                        "\n\tDid you mean to put '{}{}' after the subcommand '{}'?",
+                        Format::Good("--"),
+                        Format::Good(candidate),
+                        Format::Good(subcommand.get_name()));
                     return (suffix, Some(candidate));
                 }
             }


Test patch:
diff --git a/tests/subcommands.rs b/tests/subcommands.rs
index 78d39cde..488ffe01 100644
--- a/tests/subcommands.rs
+++ b/tests/subcommands.rs
@@ -43,8 +43,8 @@ USAGE:
 For more information try --help";
 
 #[cfg(feature = "suggestions")]
-static DYM2: &'static str = "error: Found argument '--subcmdarg' which wasn't expected, or isn't valid in this context
-\tDid you mean to put '--subcmdarg' after the subcommand 'subcmdarg'?
+static DYM2: &'static str = "error: Found argument '--subcm' which wasn't expected, or isn't valid in this context
+\tDid you mean to put '--subcmdarg' after the subcommand 'subcmd'?
 
 USAGE:
     clap-test [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND]
@@ -130,7 +130,7 @@ fn multiple_aliases() {
 #[cfg(feature="suggestions")]
 fn subcmd_did_you_mean_output() {
     assert!(test::compare_output(test::complex_app(), "clap-test subcm", DYM, true));
-    assert!(test::compare_output(test::complex_app(), "clap-test --subcmdarg foo", DYM2, true));
+    assert!(test::compare_output(test::complex_app(), "clap-test --subcm foo", DYM2, true));
 }
 
 #[test]