Skip to content

Commit 676c222

Browse files
committed
env, test: use correct exit codes on --help/--version write failure (125, 2)
1 parent 619047d commit 676c222

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/uu/env/src/env.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use std::io::stderr;
4040
use std::os::unix::ffi::OsStrExt;
4141

4242
use uucore::display::{Quotable, print_all_env_vars};
43-
use uucore::error::{ExitCode, UError, UResult, USimpleError, UUsageError};
43+
use uucore::error::{ExitCode, UClapError, UError, UResult, USimpleError, UUsageError};
4444
use uucore::line_ending::LineEnding;
4545
#[cfg(unix)]
4646
use uucore::signals::{signal_by_name_or_value, signal_name_by_value, signal_number_upper_bound};
@@ -654,7 +654,9 @@ impl EnvAppData {
654654
Err(e) => {
655655
match e.kind() {
656656
clap::error::ErrorKind::DisplayHelp
657-
| clap::error::ErrorKind::DisplayVersion => return Err(e.into()),
657+
| clap::error::ErrorKind::DisplayVersion => {
658+
return Err(e.with_exit_code(125).into())
659+
}
658660
_ => {
659661
// Use ErrorFormatter directly to handle error with shebang message callback
660662
let formatter =

src/uu/test/src/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
5050
if binary_name.ends_with('[') {
5151
// If invoked as [ we should recognize --help and --version (but not -h or -v)
5252
if args.len() == 1 && (args[0] == "--help" || args[0] == "--version") {
53-
uucore::clap_localization::handle_clap_result(
53+
uucore::clap_localization::handle_clap_result_with_exit_code(
5454
uu_app(),
5555
std::iter::once(program).chain(args.into_iter()),
56+
2,
5657
)?;
5758
return Ok(());
5859
}

0 commit comments

Comments
 (0)