Skip to content

Commit 5becc7d

Browse files
Ryujiyasuclaude
authored andcommitted
fix: match GNU error format for unrecognized options
Use single quotes and remove colon to match GNU diff/cmp output: `unrecognized option '--foobar'` instead of `unrecognized option: "--foobar"` Also use `contains` instead of `starts_with` in the integration test to handle the command prefix (e.g. `cmp: unrecognized option ...`). Follow-up to uutils#178 / uutils#179. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 59e130a commit 5becc7d

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/cmp.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Resu
217217
std::process::exit(0);
218218
}
219219
if param_str.starts_with('-') {
220-
return Err(format!("unrecognized option: {param:?}"));
220+
return Err(format!(
221+
"unrecognized option '{}'",
222+
param.to_string_lossy()
223+
));
221224
}
222225
if from.is_none() {
223226
from = Some(param);

src/params.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Resu
195195
Err(error) => return Err(error),
196196
}
197197
if param.to_string_lossy().starts_with('-') {
198-
return Err(format!("unrecognized option: {param:?}"));
198+
return Err(format!(
199+
"unrecognized option '{}'",
200+
param.to_string_lossy()
201+
));
199202
}
200203
if from.is_none() {
201204
from = Some(param);

tests/integration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ mod common {
3939
cmd.assert()
4040
.code(predicate::eq(2))
4141
.failure()
42-
.stderr(predicate::str::starts_with(
43-
"unrecognized option: \"--foobar\"",
42+
.stderr(predicate::str::contains(
43+
"unrecognized option '--foobar'",
4444
));
4545
}
4646
Ok(())

0 commit comments

Comments
 (0)