mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
Merge pull request #2844 from jfinkels/tty-uresult
tty: return UResult from uumain() function
This commit is contained in:
commit
d5312e963f
1 changed files with 9 additions and 12 deletions
|
@ -12,6 +12,7 @@
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use uucore::error::{UResult, UUsageError};
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static ABOUT: &str = "Print the file name of the terminal connected to standard input.";
|
static ABOUT: &str = "Print the file name of the terminal connected to standard input.";
|
||||||
|
@ -24,21 +25,17 @@ fn usage() -> String {
|
||||||
format!("{0} [OPTION]...", uucore::execution_phrase())
|
format!("{0} [OPTION]...", uucore::execution_phrase())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let usage = usage();
|
let usage = usage();
|
||||||
let args = args
|
let args = args
|
||||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||||
.accept_any();
|
.accept_any();
|
||||||
|
|
||||||
let matches = uu_app().usage(&usage[..]).get_matches_from_safe(args);
|
let matches = uu_app()
|
||||||
|
.usage(&usage[..])
|
||||||
let matches = match matches {
|
.get_matches_from_safe(args)
|
||||||
Ok(m) => m,
|
.map_err(|e| UUsageError::new(2, format!("{}", e)))?;
|
||||||
Err(e) => {
|
|
||||||
eprint!("{}", e);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let silent = matches.is_present(options::SILENT);
|
let silent = matches.is_present(options::SILENT);
|
||||||
|
|
||||||
|
@ -68,9 +65,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if atty::is(atty::Stream::Stdin) {
|
if atty::is(atty::Stream::Stdin) {
|
||||||
libc::EXIT_SUCCESS
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
libc::EXIT_FAILURE
|
Err(libc::EXIT_FAILURE.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue