mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-15 01:31:08 +00:00
ls: compute correct exit code on error
Note in particular that this seems to be the only tool where invalid stringly-enum values cause a different exit code than invalid arguments.
This commit is contained in:
parent
8f791da213
commit
4a1bd78f48
2 changed files with 71 additions and 2 deletions
|
|
@ -3,7 +3,7 @@
|
|||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore (ToDO) somegroup nlink tabsize dired subdired dtype colorterm
|
||||
// spell-checker:ignore (ToDO) somegroup nlink tabsize dired subdired dtype colorterm stringly
|
||||
|
||||
use clap::{
|
||||
builder::{NonEmptyStringValueParser, ValueParser},
|
||||
|
|
@ -36,6 +36,7 @@ use std::{
|
|||
};
|
||||
use term_grid::{Cell, Direction, Filling, Grid, GridOptions};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use uucore::error::USimpleError;
|
||||
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
|
||||
use uucore::fsxattr::has_acl;
|
||||
#[cfg(any(
|
||||
|
|
@ -1150,7 +1151,22 @@ impl Config {
|
|||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let command = uu_app();
|
||||
|
||||
let matches = command.try_get_matches_from(args)?;
|
||||
let matches = match command.try_get_matches_from(args) {
|
||||
// clap successfully parsed the arguments:
|
||||
Ok(matches) => matches,
|
||||
// --help, --version, etc.:
|
||||
Err(e) if e.exit_code() == 0 => {
|
||||
return Err(e.into());
|
||||
}
|
||||
// Errors in argument *values* cause exit code 1:
|
||||
Err(e) if e.kind() == clap::error::ErrorKind::InvalidValue => {
|
||||
return Err(USimpleError::new(1, e.to_string()));
|
||||
}
|
||||
// All other argument parsing errors cause exit code 2:
|
||||
Err(e) => {
|
||||
return Err(USimpleError::new(2, e.to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
let config = Config::from(&matches)?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue