mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-07 00:17:47 +00:00
ls: structure options some more
This commit is contained in:
parent
5d7a851471
commit
c454d2640c
1 changed files with 77 additions and 33 deletions
|
@ -7,6 +7,45 @@
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) cpio svgz webm somegroup nlink rmvb xspf
|
// spell-checker:ignore (ToDO) cpio svgz webm somegroup nlink rmvb xspf
|
||||||
|
|
||||||
|
// Missing features from GNU Coreutils:
|
||||||
|
// --author
|
||||||
|
// -b, --escape
|
||||||
|
// --block-size=SIZE
|
||||||
|
// -c
|
||||||
|
// -D, --Dired
|
||||||
|
// -f
|
||||||
|
// --file-type
|
||||||
|
// --format=WORD
|
||||||
|
// --full-time
|
||||||
|
// -g
|
||||||
|
// --group-directories-first
|
||||||
|
// -G, --no-group
|
||||||
|
// --si
|
||||||
|
// -H, --dereference-command-line
|
||||||
|
// --dereference-command-line-symlink-to-dir
|
||||||
|
// --hide=PATTERN
|
||||||
|
// --hyperlink[=WHEN]
|
||||||
|
// --indicator-style=WORD
|
||||||
|
// -I, --ignore
|
||||||
|
// -k, --kibibytes
|
||||||
|
// -m
|
||||||
|
// -N, --literal
|
||||||
|
// -o
|
||||||
|
// -p, --indicator-style=slash
|
||||||
|
// -q, --hide-control-chars
|
||||||
|
// --show-control-chars
|
||||||
|
// -Q, --quote-name
|
||||||
|
// --quoting-style=WORD
|
||||||
|
// --time=WORD
|
||||||
|
// --time-style=TIME_STYLE
|
||||||
|
// -T, --tabsize=COLS
|
||||||
|
// -u
|
||||||
|
// -v
|
||||||
|
// -w, --width=COLS
|
||||||
|
// -x
|
||||||
|
// -X
|
||||||
|
// -Z, --context
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
@ -70,23 +109,29 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod options {
|
pub mod options {
|
||||||
pub static ONELINE: &str = "1";
|
pub mod display {
|
||||||
pub static ALL: &str = "all";
|
pub static ONELINE: &str = "1";
|
||||||
pub static ALMOST_ALL: &str = "almost-all";
|
pub static LONG: &str = "long";
|
||||||
|
}
|
||||||
|
pub mod files {
|
||||||
|
pub static ALL: &str = "all";
|
||||||
|
pub static ALMOST_ALL: &str = "almost-all";
|
||||||
|
}
|
||||||
|
pub mod sort {
|
||||||
|
pub static SIZE: &str = "S";
|
||||||
|
pub static TIME: &str = "t";
|
||||||
|
pub static NONE: &str = "U";
|
||||||
|
pub static CTIME: &str = "c";
|
||||||
|
}
|
||||||
pub static IGNORE_BACKUPS: &str = "ignore-backups";
|
pub static IGNORE_BACKUPS: &str = "ignore-backups";
|
||||||
pub static DIRECTORY: &str = "directory";
|
pub static DIRECTORY: &str = "directory";
|
||||||
pub static CLASSIFY: &str = "classify";
|
pub static CLASSIFY: &str = "classify";
|
||||||
pub static HUMAN_READABLE: &str = "human-readable";
|
pub static HUMAN_READABLE: &str = "human-readable";
|
||||||
pub static INODE: &str = "inode";
|
pub static INODE: &str = "inode";
|
||||||
pub static DEREFERENCE: &str = "dereference";
|
pub static DEREFERENCE: &str = "dereference";
|
||||||
pub static LONG: &str = "long";
|
|
||||||
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";
|
||||||
pub static SORT_SIZE: &str = "S";
|
|
||||||
pub static SORT_TIME: &str = "t";
|
|
||||||
pub static SORT_NONE: &str = "U";
|
|
||||||
pub static SORT_CTIME: &str = "c";
|
|
||||||
pub static COLOR: &str = "color";
|
pub static COLOR: &str = "color";
|
||||||
pub static PATHS: &str = "paths";
|
pub static PATHS: &str = "paths";
|
||||||
}
|
}
|
||||||
|
@ -138,29 +183,29 @@ struct Config {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn from(options: clap::ArgMatches) -> Config {
|
fn from(options: clap::ArgMatches) -> Config {
|
||||||
let display = if options.is_present(options::LONG) {
|
let display = if options.is_present(options::display::LONG) {
|
||||||
DisplayOptions::Long
|
DisplayOptions::Long
|
||||||
} else if options.is_present(options::ONELINE) {
|
} else if options.is_present(options::display::ONELINE) {
|
||||||
DisplayOptions::OneLine
|
DisplayOptions::OneLine
|
||||||
} else {
|
} else {
|
||||||
DisplayOptions::Columns
|
DisplayOptions::Columns
|
||||||
};
|
};
|
||||||
|
|
||||||
let files = if options.is_present(options::ALL) {
|
let files = if options.is_present(options::files::ALL) {
|
||||||
Files::All
|
Files::All
|
||||||
} else if options.is_present(options::ALMOST_ALL) {
|
} else if options.is_present(options::files::ALMOST_ALL) {
|
||||||
Files::AlmostAll
|
Files::AlmostAll
|
||||||
} else {
|
} else {
|
||||||
Files::Normal
|
Files::Normal
|
||||||
};
|
};
|
||||||
|
|
||||||
let sort = if options.is_present(options::SORT_TIME) {
|
let sort = if options.is_present(options::sort::TIME) {
|
||||||
Sort::Time
|
Sort::Time
|
||||||
} else if options.is_present(options::SORT_CTIME) {
|
} else if options.is_present(options::sort::CTIME) {
|
||||||
Sort::CTime
|
Sort::CTime
|
||||||
} else if options.is_present(options::SORT_SIZE) {
|
} else if options.is_present(options::sort::SIZE) {
|
||||||
Sort::Size
|
Sort::Size
|
||||||
} else if options.is_present(options::SORT_NONE) {
|
} else if options.is_present(options::sort::NONE) {
|
||||||
Sort::None
|
Sort::None
|
||||||
} else {
|
} else {
|
||||||
Sort::Name
|
Sort::Name
|
||||||
|
@ -190,7 +235,6 @@ impl Config {
|
||||||
display,
|
display,
|
||||||
files,
|
files,
|
||||||
sort,
|
sort,
|
||||||
|
|
||||||
recursive: options.is_present(options::RECURSIVE),
|
recursive: options.is_present(options::RECURSIVE),
|
||||||
reverse: options.is_present(options::REVERSE),
|
reverse: options.is_present(options::REVERSE),
|
||||||
dereference: options.is_present(options::DEREFERENCE),
|
dereference: options.is_present(options::DEREFERENCE),
|
||||||
|
@ -217,20 +261,20 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.usage(&usage[..])
|
.usage(&usage[..])
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options ::ONELINE)
|
Arg::with_name(options::display::ONELINE)
|
||||||
.short(options ::ONELINE)
|
.short(options::display::ONELINE)
|
||||||
.help("list one file per line."),
|
.help("list one file per line."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::ALL)
|
Arg::with_name(options::files::ALL)
|
||||||
.short("a")
|
.short("a")
|
||||||
.long(options::ALL)
|
.long(options::files::ALL)
|
||||||
.help("Do not ignore hidden files (files with names that start with '.')."),
|
.help("Do not ignore hidden files (files with names that start with '.')."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::ALMOST_ALL)
|
Arg::with_name(options::files::ALMOST_ALL)
|
||||||
.short("A")
|
.short("A")
|
||||||
.long(options::ALMOST_ALL)
|
.long(options::files::ALMOST_ALL)
|
||||||
.help(
|
.help(
|
||||||
"In a directory, do not ignore all file names that start with '.', only ignore \
|
"In a directory, do not ignore all file names that start with '.', only ignore \
|
||||||
'.' and '..'.",
|
'.' and '..'.",
|
||||||
|
@ -243,8 +287,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.help("Ignore entries which end with ~."),
|
.help("Ignore entries which end with ~."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SORT_CTIME)
|
Arg::with_name(options::sort::CTIME)
|
||||||
.short(options::SORT_CTIME)
|
.short(options::sort::CTIME)
|
||||||
.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 \
|
||||||
change time (the ‘ctime’ in the inode) instead of the modification time. When \
|
change time (the ‘ctime’ in the inode) instead of the modification time. When \
|
||||||
explicitly sorting by time (--sort=time or -t) or when not using a long listing \
|
explicitly sorting by time (--sort=time or -t) or when not using a long listing \
|
||||||
|
@ -292,9 +336,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::LONG)
|
Arg::with_name(options::display::LONG)
|
||||||
.short("l")
|
.short("l")
|
||||||
.long(options::LONG)
|
.long(options::display::LONG)
|
||||||
.help("Display detailed information."),
|
.help("Display detailed information."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -317,18 +361,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.help("List the contents of all directories recursively."),
|
.help("List the contents of all directories recursively."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SORT_SIZE)
|
Arg::with_name(options::sort::SIZE)
|
||||||
.short(options::SORT_SIZE)
|
.short(options::sort::SIZE)
|
||||||
.help("Sort by file size, largest first."),
|
.help("Sort by file size, largest first."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SORT_TIME)
|
Arg::with_name(options::sort::TIME)
|
||||||
.short(options::SORT_TIME)
|
.short(options::sort::TIME)
|
||||||
.help("Sort by modification time (the 'mtime' in the inode), newest first."),
|
.help("Sort by modification time (the 'mtime' in the inode), newest first."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::SORT_NONE)
|
Arg::with_name(options::sort::NONE)
|
||||||
.short(options::SORT_NONE)
|
.short(options::sort::NONE)
|
||||||
.help("Do not sort; list the files in whatever order they are stored in the \
|
.help("Do not sort; list the files in whatever order they are stored in the \
|
||||||
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.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue