1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-07 00:17:47 +00:00

ls: simplify --color and remove it on windows

This commit is contained in:
Terts Diepraam 2021-03-14 23:34:52 +01:00
parent c86c18cbb5
commit 7bde2e78a9

View file

@ -138,6 +138,7 @@ pub mod options {
pub static NUMERIC_UID_GID: &str = "numeric-uid-gid"; pub static NUMERIC_UID_GID: &str = "numeric-uid-gid";
pub static REVERSE: &str = "reverse"; pub static REVERSE: &str = "reverse";
pub static RECURSIVE: &str = "recursive"; pub static RECURSIVE: &str = "recursive";
#[cfg(unix)]
pub static COLOR: &str = "color"; pub static COLOR: &str = "color";
pub static PATHS: &str = "paths"; pub static PATHS: &str = "paths";
} }
@ -230,17 +231,13 @@ impl Config {
}; };
#[cfg(unix)] #[cfg(unix)]
let color = if options.is_present(options::COLOR) { let color = match options.value_of(options::COLOR) {
match options.value_of(options::COLOR) { None => options.is_present(options::COLOR),
None => atty::is(atty::Stream::Stdout), Some(val) => match val {
Some(val) => match val { "" | "always" | "yes" | "force" => true,
"" | "always" | "yes" | "force" => true, "auto" | "tty" | "if-tty" => atty::is(atty::Stream::Stdout),
"auto" | "tty" | "if-tty" => atty::is(atty::Stream::Stdout), /* "never" | "no" | "none" | */ _ => false,
/* "never" | "no" | "none" | */ _ => false, },
},
}
} else {
false
}; };
let size_format = if options.is_present(options::HUMAN_READABLE) { let size_format = if options.is_present(options::HUMAN_READABLE) {
@ -275,7 +272,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = get_usage();
let matches = App::new(executable!()) let mut app = App::new(executable!())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.usage(&usage[..]) .usage(&usage[..])
@ -319,7 +316,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.help("If the long listing format (e.g., -l, -o) is being used, print the status \ .help("If the long listing format (e.g., -l, -o) is being used, print the status \
access time instead of the modification time. When explicitly sorting by time \ access time instead of the modification time. When explicitly sorting by time \
(--sort=time or -t) or when not using a long listing format, sort according to the \ (--sort=time or -t) or when not using a long listing format, sort according to the \
status change time.") access time.")
) )
.arg( .arg(
Arg::with_name(options::DIRECTORY) Arg::with_name(options::DIRECTORY)
@ -404,16 +401,21 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
directory. This is especially useful when listing very large directories, \ directory. This is especially useful when listing very large directories, \
since not doing any sorting can be noticeably faster.", since not doing any sorting can be noticeably faster.",
)) ))
.arg( .arg(Arg::with_name(options::PATHS).multiple(true).takes_value(true));
#[cfg(unix)]
{
app = app.arg(
Arg::with_name(options::COLOR) Arg::with_name(options::COLOR)
.long(options::COLOR) .long(options::COLOR)
.help("Color output based on file type.") .help("Color output based on file type.")
.takes_value(true) .takes_value(true)
.require_equals(true) .require_equals(true)
.min_values(0), .min_values(0),
) );
.arg(Arg::with_name(options::PATHS).multiple(true).takes_value(true)) }
.get_matches_from(args);
let matches = app.get_matches_from(args);
let locs = matches let locs = matches
.values_of(options::PATHS) .values_of(options::PATHS)