diff --git a/examples/derive_ref/interop_tests.md b/examples/derive_ref/interop_tests.md index 4aa4bb43..b6dc3782 100644 --- a/examples/derive_ref/interop_tests.md +++ b/examples/derive_ref/interop_tests.md @@ -37,7 +37,7 @@ $ interop_augment_args --unknown ? failed 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: interop_augment_args[EXE] [OPTIONS] @@ -75,7 +75,7 @@ $ interop_augment_subcommands derived --unknown ? failed 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: interop_augment_subcommands[EXE] derived [OPTIONS] @@ -150,7 +150,7 @@ $ interop_hand_subcommand add --unknown ? failed 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: interop_hand_subcommand[EXE] add [NAME]... @@ -251,7 +251,7 @@ $ interop_flatten_hand_args --unknown ? failed 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: interop_flatten_hand_args[EXE] [OPTIONS] diff --git a/examples/tutorial_builder/04_01_enum.md b/examples/tutorial_builder/04_01_enum.md index 33b3d1f6..cea785a7 100644 --- a/examples/tutorial_builder/04_01_enum.md +++ b/examples/tutorial_builder/04_01_enum.md @@ -21,7 +21,7 @@ Tortoise $ 04_01_enum medium ? failed error: "medium" isn't a valid value for '' - [possible values: fast, slow] + [possible values: fast, slow] For more information try --help diff --git a/examples/tutorial_builder/04_01_possible.md b/examples/tutorial_builder/04_01_possible.md index ff2ef9fe..5058ae53 100644 --- a/examples/tutorial_builder/04_01_possible.md +++ b/examples/tutorial_builder/04_01_possible.md @@ -21,7 +21,7 @@ Tortoise $ 04_01_possible medium ? failed error: "medium" isn't a valid value for '' - [possible values: fast, slow] + [possible values: fast, slow] For more information try --help diff --git a/examples/tutorial_derive/04_01_enum.md b/examples/tutorial_derive/04_01_enum.md index 7bc5ff6a..5d16ff45 100644 --- a/examples/tutorial_derive/04_01_enum.md +++ b/examples/tutorial_derive/04_01_enum.md @@ -21,7 +21,7 @@ Tortoise $ 04_01_enum_derive medium ? failed error: "medium" isn't a valid value for '' - [possible values: fast, slow] + [possible values: fast, slow] For more information try --help diff --git a/src/error/format.rs b/src/error/format.rs index 1e21f624..5f4ba425 100644 --- a/src/error/format.rs +++ b/src/error/format.rs @@ -6,6 +6,7 @@ use crate::builder::StyledStr; use crate::error::ContextKind; use crate::error::ContextValue; use crate::error::ErrorKind; +use crate::output::TAB; /// Defines how to format an error for displaying to the user pub trait ErrorFormatter: Sized { @@ -110,7 +111,8 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool { ContextValue::Strings(values) => { styled.none(":"); for v in values { - styled.none("\n "); + styled.none("\n"); + styled.none(TAB); 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); if let Some(ContextValue::Strings(possible_values)) = possible_values { 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() { for v in elements { 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); 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.none("?"); } @@ -193,7 +199,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool { let valid_sub = error.get(ContextKind::SuggestedSubcommand); 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.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 { styled.none("The following required arguments were not provided:"); for v in invalid_arg { - styled.none("\n "); + styled.none("\n"); + styled.none(TAB); styled.good(&**v); } 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_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.good(valid_arg); styled.none("' after the subcommand '"); @@ -345,7 +356,9 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool { styled.none("'?"); } (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.none("'?"); } @@ -355,16 +368,20 @@ fn write_dynamic_context(error: &crate::Error, styled: &mut StyledStr) -> bool { let invalid_arg = error.get(ContextKind::InvalidArg); if let Some(ContextValue::String(invalid_arg)) = invalid_arg { if invalid_arg.starts_with('-') { + styled.none("\n\n"); + styled.none(TAB); 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 )); } let trailing_arg = error.get(ContextKind::TrailingArg); if trailing_arg == Some(&ContextValue::Bool(true)) { + styled.none("\n\n"); + styled.none(TAB); 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 )); } diff --git a/tests/builder/flags.rs b/tests/builder/flags.rs index 3759446b..03e365f4 100644 --- a/tests/builder/flags.rs +++ b/tests/builder/flags.rs @@ -4,7 +4,7 @@ use clap::{arg, Arg, ArgAction, Command}; const USE_FLAG_AS_ARGUMENT: &str = "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: mycat [OPTIONS] [filename] @@ -181,7 +181,7 @@ fn issue_2308_multiple_dashes() { static MULTIPLE_DASHES: &str = "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: test diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs index 1a3e81f5..c1084e0c 100644 --- a/tests/builder/opts.rs +++ b/tests/builder/opts.rs @@ -6,9 +6,9 @@ use clap::{arg, error::ErrorKind, Arg, ArgAction, ArgMatches, Command}; static DYM: &str = "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: clap-test --option ... [positional] [positional2] [positional3]... @@ -20,9 +20,9 @@ For more information try --help static DYM_ISSUE_1073: &str = "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: ripgrep-616 --files-without-match diff --git a/tests/builder/possible_values.rs b/tests/builder/possible_values.rs index 29aeb1bb..f6ff0256 100644 --- a/tests/builder/possible_values.rs +++ b/tests/builder/possible_values.rs @@ -4,32 +4,32 @@ use clap::{builder::PossibleValue, error::ErrorKind, Arg, ArgAction, Command}; #[cfg(feature = "suggestions")] static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O