mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
false: Align behavior to true and GNU
This commit is contained in:
parent
b29e219e4d
commit
dcf177f908
1 changed files with 31 additions and 4 deletions
|
@ -4,16 +4,43 @@
|
||||||
// *
|
// *
|
||||||
// * For the full copyright and license information, please view the LICENSE
|
// * For the full copyright and license information, please view the LICENSE
|
||||||
// * file that was distributed with this source code.
|
// * file that was distributed with this source code.
|
||||||
|
use clap::{App, AppSettings, ErrorKind};
|
||||||
|
use std::io::Write;
|
||||||
|
use uucore::error::{set_exit_code, UResult};
|
||||||
|
|
||||||
use clap::App;
|
static ABOUT: &str = "
|
||||||
use uucore::error::UResult;
|
Returns false, an unsuccessful exit status.
|
||||||
|
|
||||||
|
Immediately returns with the exit status `1`. When invoked with one of the recognized options it
|
||||||
|
will try to write the help or version text. Any IO error during this operation is diagnosed, yet
|
||||||
|
the program will also return `1`.
|
||||||
|
";
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
uu_app().get_matches_from(args);
|
let app = uu_app();
|
||||||
Err(1.into())
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
if let Err(err) = app.try_get_matches_from(args) {
|
||||||
|
if let ErrorKind::DisplayHelp | ErrorKind::DisplayVersion = err.kind {
|
||||||
|
if let Err(print_fail) = err.print() {
|
||||||
|
// Try to display this error.
|
||||||
|
let _ = writeln!(std::io::stderr(), "{}: {}", uucore::util_name(), print_fail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app<'a>() -> App<'a> {
|
pub fn uu_app<'a>() -> App<'a> {
|
||||||
App::new(uucore::util_name())
|
App::new(uucore::util_name())
|
||||||
|
.version(clap::crate_version!())
|
||||||
|
.about(ABOUT)
|
||||||
|
.setting(AppSettings::InferLongArgs)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue