mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
fix(error): Make whitespace consistent with self/help
Sometimes errors would use a tab, sometimes four spaces. This makes it always four spaces and shares a definition with help.
This commit is contained in:
parent
439c9e7a91
commit
671914b590
10 changed files with 54 additions and 37 deletions
|
@ -37,7 +37,7 @@ $ interop_augment_args --unknown
|
||||||
? failed
|
? failed
|
||||||
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
interop_augment_args[EXE] [OPTIONS]
|
interop_augment_args[EXE] [OPTIONS]
|
||||||
|
@ -75,7 +75,7 @@ $ interop_augment_subcommands derived --unknown
|
||||||
? failed
|
? failed
|
||||||
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
interop_augment_subcommands[EXE] derived [OPTIONS]
|
interop_augment_subcommands[EXE] derived [OPTIONS]
|
||||||
|
@ -150,7 +150,7 @@ $ interop_hand_subcommand add --unknown
|
||||||
? failed
|
? failed
|
||||||
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
interop_hand_subcommand[EXE] add [NAME]...
|
interop_hand_subcommand[EXE] add [NAME]...
|
||||||
|
@ -251,7 +251,7 @@ $ interop_flatten_hand_args --unknown
|
||||||
? failed
|
? failed
|
||||||
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
error: Found argument '--unknown' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
If you tried to supply `--unknown` as a value rather than a flag, use `-- --unknown`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
interop_flatten_hand_args[EXE] [OPTIONS]
|
interop_flatten_hand_args[EXE] [OPTIONS]
|
||||||
|
|
|
@ -21,7 +21,7 @@ Tortoise
|
||||||
$ 04_01_enum medium
|
$ 04_01_enum medium
|
||||||
? failed
|
? failed
|
||||||
error: "medium" isn't a valid value for '<MODE>'
|
error: "medium" isn't a valid value for '<MODE>'
|
||||||
[possible values: fast, slow]
|
[possible values: fast, slow]
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ Tortoise
|
||||||
$ 04_01_possible medium
|
$ 04_01_possible medium
|
||||||
? failed
|
? failed
|
||||||
error: "medium" isn't a valid value for '<MODE>'
|
error: "medium" isn't a valid value for '<MODE>'
|
||||||
[possible values: fast, slow]
|
[possible values: fast, slow]
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ Tortoise
|
||||||
$ 04_01_enum_derive medium
|
$ 04_01_enum_derive medium
|
||||||
? failed
|
? failed
|
||||||
error: "medium" isn't a valid value for '<MODE>'
|
error: "medium" isn't a valid value for '<MODE>'
|
||||||
[possible values: fast, slow]
|
[possible values: fast, slow]
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::builder::StyledStr;
|
||||||
use crate::error::ContextKind;
|
use crate::error::ContextKind;
|
||||||
use crate::error::ContextValue;
|
use crate::error::ContextValue;
|
||||||
use crate::error::ErrorKind;
|
use crate::error::ErrorKind;
|
||||||
|
use crate::output::TAB;
|
||||||
|
|
||||||
/// Defines how to format an error for displaying to the user
|
/// Defines how to format an error for displaying to the user
|
||||||
pub trait ErrorFormatter: Sized {
|
pub trait ErrorFormatter: Sized {
|
||||||
|
@ -110,7 +111,8 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
ContextValue::Strings(values) => {
|
ContextValue::Strings(values) => {
|
||||||
styled.none(":");
|
styled.none(":");
|
||||||
for v in values {
|
for v in values {
|
||||||
styled.none("\n ");
|
styled.none("\n");
|
||||||
|
styled.none(TAB);
|
||||||
styled.warning(&**v);
|
styled.warning(&**v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +163,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
let possible_values = error.get(ContextKind::ValidValue);
|
let possible_values = error.get(ContextKind::ValidValue);
|
||||||
if let Some(ContextValue::Strings(possible_values)) = possible_values {
|
if let Some(ContextValue::Strings(possible_values)) = possible_values {
|
||||||
if !possible_values.is_empty() {
|
if !possible_values.is_empty() {
|
||||||
styled.none("\n\t[possible values: ");
|
styled.none("\n");
|
||||||
|
styled.none(TAB);
|
||||||
|
styled.none("[possible values: ");
|
||||||
if let Some((last, elements)) = possible_values.split_last() {
|
if let Some((last, elements)) = possible_values.split_last() {
|
||||||
for v in elements {
|
for v in elements {
|
||||||
styled.good(escape(v));
|
styled.good(escape(v));
|
||||||
|
@ -175,7 +179,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
|
|
||||||
let suggestion = error.get(ContextKind::SuggestedValue);
|
let suggestion = error.get(ContextKind::SuggestedValue);
|
||||||
if let Some(ContextValue::String(suggestion)) = suggestion {
|
if let Some(ContextValue::String(suggestion)) = suggestion {
|
||||||
styled.none("\n\n\tDid you mean ");
|
styled.none("\n\n");
|
||||||
|
styled.none(TAB);
|
||||||
|
styled.none("Did you mean ");
|
||||||
styled.good(quote(suggestion));
|
styled.good(quote(suggestion));
|
||||||
styled.none("?");
|
styled.none("?");
|
||||||
}
|
}
|
||||||
|
@ -193,7 +199,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
|
|
||||||
let valid_sub = error.get(ContextKind::SuggestedSubcommand);
|
let valid_sub = error.get(ContextKind::SuggestedSubcommand);
|
||||||
if let Some(ContextValue::String(valid_sub)) = valid_sub {
|
if let Some(ContextValue::String(valid_sub)) = valid_sub {
|
||||||
styled.none("\n\n\tDid you mean ");
|
styled.none("\n\n");
|
||||||
|
styled.none(TAB);
|
||||||
|
styled.none("Did you mean ");
|
||||||
styled.good(valid_sub);
|
styled.good(valid_sub);
|
||||||
styled.none("?");
|
styled.none("?");
|
||||||
}
|
}
|
||||||
|
@ -216,7 +224,8 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
if let Some(ContextValue::Strings(invalid_arg)) = invalid_arg {
|
if let Some(ContextValue::Strings(invalid_arg)) = invalid_arg {
|
||||||
styled.none("The following required arguments were not provided:");
|
styled.none("The following required arguments were not provided:");
|
||||||
for v in invalid_arg {
|
for v in invalid_arg {
|
||||||
styled.none("\n ");
|
styled.none("\n");
|
||||||
|
styled.none(TAB);
|
||||||
styled.good(&**v);
|
styled.good(&**v);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
@ -337,7 +346,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
Some(ContextValue::String(valid_sub)),
|
Some(ContextValue::String(valid_sub)),
|
||||||
Some(ContextValue::String(valid_arg)),
|
Some(ContextValue::String(valid_arg)),
|
||||||
) => {
|
) => {
|
||||||
styled.none("\n\n\tDid you mean ");
|
styled.none("\n\n");
|
||||||
|
styled.none(TAB);
|
||||||
|
styled.none("Did you mean ");
|
||||||
styled.none("to put '");
|
styled.none("to put '");
|
||||||
styled.good(valid_arg);
|
styled.good(valid_arg);
|
||||||
styled.none("' after the subcommand '");
|
styled.none("' after the subcommand '");
|
||||||
|
@ -345,7 +356,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
styled.none("'?");
|
styled.none("'?");
|
||||||
}
|
}
|
||||||
(None, Some(ContextValue::String(valid_arg))) => {
|
(None, Some(ContextValue::String(valid_arg))) => {
|
||||||
styled.none("\n\n\tDid you mean '");
|
styled.none("\n\n");
|
||||||
|
styled.none(TAB);
|
||||||
|
styled.none("Did you mean '");
|
||||||
styled.good(valid_arg);
|
styled.good(valid_arg);
|
||||||
styled.none("'?");
|
styled.none("'?");
|
||||||
}
|
}
|
||||||
|
@ -355,16 +368,20 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool {
|
||||||
let invalid_arg = error.get(ContextKind::InvalidArg);
|
let invalid_arg = error.get(ContextKind::InvalidArg);
|
||||||
if let Some(ContextValue::String(invalid_arg)) = invalid_arg {
|
if let Some(ContextValue::String(invalid_arg)) = invalid_arg {
|
||||||
if invalid_arg.starts_with('-') {
|
if invalid_arg.starts_with('-') {
|
||||||
|
styled.none("\n\n");
|
||||||
|
styled.none(TAB);
|
||||||
styled.none(format!(
|
styled.none(format!(
|
||||||
"\n\n\tIf you tried to supply `{}` as a value rather than a flag, use `-- {}`",
|
"If you tried to supply `{}` as a value rather than a flag, use `-- {}`",
|
||||||
invalid_arg, invalid_arg
|
invalid_arg, invalid_arg
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let trailing_arg = error.get(ContextKind::TrailingArg);
|
let trailing_arg = error.get(ContextKind::TrailingArg);
|
||||||
if trailing_arg == Some(&ContextValue::Bool(true)) {
|
if trailing_arg == Some(&ContextValue::Bool(true)) {
|
||||||
|
styled.none("\n\n");
|
||||||
|
styled.none(TAB);
|
||||||
styled.none(format!(
|
styled.none(format!(
|
||||||
"\n\n\tIf you tried to supply `{}` as a subcommand, remove the '--' before it.",
|
"If you tried to supply `{}` as a subcommand, remove the '--' before it.",
|
||||||
invalid_arg
|
invalid_arg
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use clap::{arg, Arg, ArgAction, Command};
|
||||||
const USE_FLAG_AS_ARGUMENT: &str =
|
const USE_FLAG_AS_ARGUMENT: &str =
|
||||||
"error: Found argument '--another-flag' which wasn't expected, or isn't valid in this context
|
"error: Found argument '--another-flag' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tIf you tried to supply `--another-flag` as a value rather than a flag, use `-- --another-flag`
|
If you tried to supply `--another-flag` as a value rather than a flag, use `-- --another-flag`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
mycat [OPTIONS] [filename]
|
mycat [OPTIONS] [filename]
|
||||||
|
@ -181,7 +181,7 @@ fn issue_2308_multiple_dashes() {
|
||||||
static MULTIPLE_DASHES: &str =
|
static MULTIPLE_DASHES: &str =
|
||||||
"error: Found argument '-----' which wasn't expected, or isn't valid in this context
|
"error: Found argument '-----' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
If you tried to supply `-----` as a value rather than a flag, use `-- -----`
|
If you tried to supply `-----` as a value rather than a flag, use `-- -----`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
test <arg>
|
test <arg>
|
||||||
|
|
|
@ -6,9 +6,9 @@ use clap::{arg, error::ErrorKind, Arg, ArgAction, ArgMatches, Command};
|
||||||
static DYM: &str =
|
static DYM: &str =
|
||||||
"error: Found argument '--optio' which wasn't expected, or isn't valid in this context
|
"error: Found argument '--optio' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tDid you mean '--option'?
|
Did you mean '--option'?
|
||||||
|
|
||||||
\tIf you tried to supply `--optio` as a value rather than a flag, use `-- --optio`
|
If you tried to supply `--optio` as a value rather than a flag, use `-- --optio`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
clap-test --option <opt>... [positional] [positional2] [positional3]...
|
clap-test --option <opt>... [positional] [positional2] [positional3]...
|
||||||
|
@ -20,9 +20,9 @@ For more information try --help
|
||||||
static DYM_ISSUE_1073: &str =
|
static DYM_ISSUE_1073: &str =
|
||||||
"error: Found argument '--files-without-matches' which wasn't expected, or isn't valid in this context
|
"error: Found argument '--files-without-matches' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tDid you mean '--files-without-match'?
|
Did you mean '--files-without-match'?
|
||||||
|
|
||||||
\tIf you tried to supply `--files-without-matches` as a value rather than a flag, use `-- --files-without-matches`
|
If you tried to supply `--files-without-matches` as a value rather than a flag, use `-- --files-without-matches`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
ripgrep-616 --files-without-match
|
ripgrep-616 --files-without-match
|
||||||
|
|
|
@ -4,32 +4,32 @@ use clap::{builder::PossibleValue, error::ErrorKind, Arg, ArgAction, Command};
|
||||||
|
|
||||||
#[cfg(feature = "suggestions")]
|
#[cfg(feature = "suggestions")]
|
||||||
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: slow, fast, \"ludicrous speed\"]
|
[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
\tDid you mean \"slow\"?
|
Did you mean \"slow\"?
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
";
|
";
|
||||||
|
|
||||||
#[cfg(not(feature = "suggestions"))]
|
#[cfg(not(feature = "suggestions"))]
|
||||||
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: slow, fast, \"ludicrous speed\"]
|
[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
";
|
";
|
||||||
|
|
||||||
#[cfg(feature = "suggestions")]
|
#[cfg(feature = "suggestions")]
|
||||||
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: slow, fast, \"ludicrous speed\"]
|
[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
\tDid you mean \"ludicrous speed\"?
|
Did you mean \"ludicrous speed\"?
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
";
|
";
|
||||||
|
|
||||||
#[cfg(not(feature = "suggestions"))]
|
#[cfg(not(feature = "suggestions"))]
|
||||||
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: slow, fast, \"ludicrous speed\"]
|
[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
";
|
";
|
||||||
|
@ -295,7 +295,7 @@ fn missing_possible_value_error() {
|
||||||
|
|
||||||
static MISSING_PV_ERROR: &str =
|
static MISSING_PV_ERROR: &str =
|
||||||
"error: The argument '-O <option>' requires a value but none was supplied
|
"error: The argument '-O <option>' requires a value but none was supplied
|
||||||
\t[possible values: slow, fast, \"ludicrous speed\"]
|
[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
For more information try --help
|
For more information try --help
|
||||||
";
|
";
|
||||||
|
|
|
@ -31,7 +31,7 @@ Options:
|
||||||
#[cfg(feature = "suggestions")]
|
#[cfg(feature = "suggestions")]
|
||||||
static DYM_SUBCMD: &str = "error: The subcommand 'subcm' wasn't recognized
|
static DYM_SUBCMD: &str = "error: The subcommand 'subcm' wasn't recognized
|
||||||
|
|
||||||
Did you mean 'subcmd'?
|
Did you mean 'subcmd'?
|
||||||
|
|
||||||
If you believe you received this message in error, try re-running with 'dym -- subcm'
|
If you believe you received this message in error, try re-running with 'dym -- subcm'
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ For more information try --help
|
||||||
#[cfg(feature = "suggestions")]
|
#[cfg(feature = "suggestions")]
|
||||||
static DYM_SUBCMD_AMBIGUOUS: &str = "error: The subcommand 'te' wasn't recognized
|
static DYM_SUBCMD_AMBIGUOUS: &str = "error: The subcommand 'te' wasn't recognized
|
||||||
|
|
||||||
Did you mean 'test' or 'temp'?
|
Did you mean 'test' or 'temp'?
|
||||||
|
|
||||||
If you believe you received this message in error, try re-running with 'dym -- te'
|
If you believe you received this message in error, try re-running with 'dym -- te'
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ For more information try --help
|
||||||
static SUBCMD_AFTER_DOUBLE_DASH: &str =
|
static SUBCMD_AFTER_DOUBLE_DASH: &str =
|
||||||
"error: Found argument 'subcmd' which wasn't expected, or isn't valid in this context
|
"error: Found argument 'subcmd' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tIf you tried to supply `subcmd` as a subcommand, remove the '--' before it.
|
If you tried to supply `subcmd` as a subcommand, remove the '--' before it.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
cmd [COMMAND]
|
cmd [COMMAND]
|
||||||
|
@ -177,9 +177,9 @@ fn subcmd_did_you_mean_output_arg() {
|
||||||
static EXPECTED: &str =
|
static EXPECTED: &str =
|
||||||
"error: Found argument '--subcmarg' which wasn't expected, or isn't valid in this context
|
"error: Found argument '--subcmarg' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tDid you mean to put '--subcmdarg' after the subcommand 'subcmd'?
|
Did you mean to put '--subcmdarg' after the subcommand 'subcmd'?
|
||||||
|
|
||||||
\tIf you tried to supply `--subcmarg` as a value rather than a flag, use `-- --subcmarg`
|
If you tried to supply `--subcmarg` as a value rather than a flag, use `-- --subcmarg`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
dym [COMMAND]
|
dym [COMMAND]
|
||||||
|
@ -200,7 +200,7 @@ fn subcmd_did_you_mean_output_arg_false_positives() {
|
||||||
static EXPECTED: &str =
|
static EXPECTED: &str =
|
||||||
"error: Found argument '--subcmarg' which wasn't expected, or isn't valid in this context
|
"error: Found argument '--subcmarg' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tIf you tried to supply `--subcmarg` as a value rather than a flag, use `-- --subcmarg`
|
If you tried to supply `--subcmarg` as a value rather than a flag, use `-- --subcmarg`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
dym [COMMAND]
|
dym [COMMAND]
|
||||||
|
@ -529,7 +529,7 @@ For more information try help
|
||||||
static BAZ_EXPECTED: &str = "\
|
static BAZ_EXPECTED: &str = "\
|
||||||
error: The subcommand 'baz' wasn't recognized
|
error: The subcommand 'baz' wasn't recognized
|
||||||
|
|
||||||
\tDid you mean 'bar'?
|
Did you mean 'bar'?
|
||||||
|
|
||||||
If you believe you received this message in error, try re-running with ' -- baz'
|
If you believe you received this message in error, try re-running with ' -- baz'
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ stdout = ""
|
||||||
stderr = """
|
stderr = """
|
||||||
error: Found argument '--unknown-argument' which wasn't expected, or isn't valid in this context
|
error: Found argument '--unknown-argument' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
\tIf you tried to supply `--unknown-argument` as a value rather than a flag, use `-- --unknown-argument`
|
If you tried to supply `--unknown-argument` as a value rather than a flag, use `-- --unknown-argument`
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
stdio-fixture[EXE] [OPTIONS] [COMMAND]
|
stdio-fixture[EXE] [OPTIONS] [COMMAND]
|
||||||
|
|
Loading…
Reference in a new issue