Skip to content

Commit 9b5e8ec

Browse files
committed
Improve error reporting on invalid argument arity
1 parent 0e5d8d7 commit 9b5e8ec

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Difftastic now requires Rust 1.77 or later to build.
1313
Difftastic no longer uses jemalloc on any Windows builds. Previously
1414
jemalloc was only disabled for MSVC.
1515

16+
### Command Line Interface
17+
18+
Improved error reporting when invoked with an invalid number of
19+
arguments.
20+
1621
## 0.67 (released 16 November 2025)
1722

1823
### Parsing

src/options.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ pub(crate) fn parse_args() -> Mode {
897897
)
898898
}
899899
[display_path, lhs_tmp_file, _lhs_hash, lhs_mode, rhs_tmp_file, _rhs_hash, rhs_mode] => {
900-
// https://git-scm.com/docs/git#Documentation/git.txt-codeGITEXTERNALDIFFcode
900+
// 7 arguments, per https://git-scm.com/docs/git#Documentation/git.txt-codeGITEXTERNALDIFFcode
901901
(
902902
display_path.to_string_lossy().to_string(),
903903
FileArgument::from_path_argument(lhs_tmp_file),
@@ -953,17 +953,29 @@ pub(crate) fn parse_args() -> Mode {
953953
}
954954
_ => {
955955
if !args.is_empty() {
956+
let formatted_args = args
957+
.iter()
958+
.map(|arg| arg.to_string_lossy())
959+
.collect::<Vec<_>>();
960+
961+
let bin_name = if let Some(first_arg) = std::env::args_os().next() {
962+
first_arg.to_string_lossy().to_string()
963+
} else {
964+
env!("CARGO_BIN_NAME").to_owned()
965+
};
966+
956967
print_error(
957968
&format!(
958-
"Difftastic does not support being called with {} argument{}.\n",
969+
"Difftastic does not support being called with {} argument{}.\n\nYou can pass 2 arguments, or arguments in the form used by GIT_EXTERNAL_DIFF (7 or 9 arguments). See --help for more details. \n\nFor reference, difftastic was invoked as `{} {}`.\n",
959970
args.len(),
960-
if args.len() == 1 { "" } else { "s" }
971+
if args.len() == 1 { "" } else { "s" },
972+
bin_name,
973+
formatted_args.join(" "),
961974
),
962975
use_color,
963976
);
964977
}
965-
eprintln!("USAGE:\n\n {}\n", USAGE);
966-
eprintln!("For more information try --help");
978+
967979
std::process::exit(EXIT_BAD_ARGUMENTS);
968980
}
969981
};

0 commit comments

Comments
 (0)