Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/uu/false/src/false.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@
// file that was distributed with this source code.
use clap::{Arg, ArgAction, Command};
use std::{ffi::OsString, io::Write};
use uucore::error::{UResult, set_exit_code};

use uucore::translate;

#[uucore::main(no_signals)]
// TODO: modify proc macro to allow no-result uumain
#[expect(clippy::unnecessary_wraps, reason = "proc macro requires UResult")]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Mirror GNU options, always return `1`. In particular even the 'successful' cases of no-op,
// and the interrupted display of help and version should return `1`. Also, we return Ok in all
// paths to avoid the allocation of an error object, an operation that could, in theory, fail
// and unwind through the standard library allocation handling machinery.
set_exit_code(1);

// uucore::main does not support no-result
// also remove SIGPIPE overhead
pub fn uumain(args: impl uucore::Args) -> i32 {
let args: Vec<OsString> = args.collect();
if args.len() != 2 {
return Ok(());
return 1;
}

// args[0] is the name of the binary.
Expand All @@ -29,14 +20,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} else if args[1] == "--version" {
write!(std::io::stdout(), "{}", uu_app().render_version())
} else {
Ok(())
return 1;
};

if let Err(print_fail) = error {
let _ = writeln!(std::io::stderr(), "{}: {print_fail}", uucore::util_name());
}

Ok(())
1
}

pub fn uu_app() -> Command {
Expand Down
18 changes: 7 additions & 11 deletions src/uu/true/src/true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
// file that was distributed with this source code.
use clap::{Arg, ArgAction, Command};
use std::{ffi::OsString, io::Write};
use uucore::error::{UResult, set_exit_code};

use uucore::translate;

#[uucore::main(no_signals)]
// TODO: modify proc macro to allow no-result uumain
#[expect(clippy::unnecessary_wraps, reason = "proc macro requires UResult")]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// uucore::main does not support no-result
// also remove SIGPIPE overhead
pub fn uumain(args: impl uucore::Args) -> i32 {
let args: Vec<OsString> = args.collect();
if args.len() != 2 {
return Ok(());
return 0;
}

// args[0] is the name of the binary.
Expand All @@ -23,7 +20,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} else if args[1] == "--version" {
write!(std::io::stdout(), "{}", uu_app().render_version())
} else {
Ok(())
return 0;
};

if let Err(print_fail) = error {
Expand All @@ -32,10 +29,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Mirror GNU options. When failing to print warnings or version flags, then we exit
// with FAIL. This avoids allocation some error information which may result in yet
// other types of failure.
set_exit_code(1);
return 1;
}

Ok(())
0
}

pub fn uu_app() -> Command {
Expand Down
Loading