diff --git a/.vscode/cspell.dictionaries/people.wordlist.txt b/.vscode/cspell.dictionaries/people.wordlist.txt index 40573383613..8fe38d88538 100644 --- a/.vscode/cspell.dictionaries/people.wordlist.txt +++ b/.vscode/cspell.dictionaries/people.wordlist.txt @@ -179,3 +179,4 @@ Smigle00 anonymousknight kwantam nicoo +gmnsii diff --git a/.vscode/cspell.dictionaries/shell.wordlist.txt b/.vscode/cspell.dictionaries/shell.wordlist.txt index 4ed281efbff..16d7b25e997 100644 --- a/.vscode/cspell.dictionaries/shell.wordlist.txt +++ b/.vscode/cspell.dictionaries/shell.wordlist.txt @@ -93,6 +93,7 @@ rollup sed selinuxenabled sestatus +vdir wslpath xargs diff --git a/Cargo.lock b/Cargo.lock index bc7431baaf3..c1dec695dfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,6 +368,7 @@ dependencies = [ "uu_date", "uu_dd", "uu_df", + "uu_dir", "uu_dircolors", "uu_dirname", "uu_du", @@ -445,6 +446,7 @@ dependencies = [ "uu_unlink", "uu_uptime", "uu_users", + "uu_vdir", "uu_wc", "uu_who", "uu_whoami", @@ -2376,6 +2378,16 @@ dependencies = [ "uucore", ] +[[package]] +name = "uu_dir" +version = "0.0.13" +dependencies = [ + "clap 3.1.8", + "selinux", + "uu_ls", + "uucore", +] + [[package]] name = "uu_dircolors" version = "0.0.13" @@ -3127,6 +3139,16 @@ dependencies = [ "uucore", ] +[[package]] +name = "uu_vdir" +version = "0.0.13" +dependencies = [ + "clap 3.1.8", + "selinux", + "uu_ls", + "uucore", +] + [[package]] name = "uu_wc" version = "0.0.13" diff --git a/Cargo.toml b/Cargo.toml index 12959ad35ad..f5932b1cf6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ feat_common_core = [ "cut", "date", "df", + "dir", "dircolors", "dirname", "dd", @@ -100,6 +101,7 @@ feat_common_core = [ "unexpand", "uniq", "unlink", + "vdir", "wc", "yes", ] @@ -276,6 +278,7 @@ cut = { optional=true, version="0.0.13", package="uu_cut", path="src/uu/cut date = { optional=true, version="0.0.13", package="uu_date", path="src/uu/date" } dd = { optional=true, version="0.0.13", package="uu_dd", path="src/uu/dd" } df = { optional=true, version="0.0.13", package="uu_df", path="src/uu/df" } +dir = { optional=true, version="0.0.13", package="uu_dir", path="src/uu/dir" } dircolors= { optional=true, version="0.0.13", package="uu_dircolors", path="src/uu/dircolors" } dirname = { optional=true, version="0.0.13", package="uu_dirname", path="src/uu/dirname" } du = { optional=true, version="0.0.13", package="uu_du", path="src/uu/du" } @@ -352,6 +355,7 @@ uniq = { optional=true, version="0.0.13", package="uu_uniq", path="src/uu/un unlink = { optional=true, version="0.0.13", package="uu_unlink", path="src/uu/unlink" } uptime = { optional=true, version="0.0.13", package="uu_uptime", path="src/uu/uptime" } users = { optional=true, version="0.0.13", package="uu_users", path="src/uu/users" } +vdir = { optional=true, version="0.0.13", package="uu_vdir", path="src/uu/vdir" } wc = { optional=true, version="0.0.13", package="uu_wc", path="src/uu/wc" } who = { optional=true, version="0.0.13", package="uu_who", path="src/uu/who" } whoami = { optional=true, version="0.0.13", package="uu_whoami", path="src/uu/whoami" } diff --git a/GNUmakefile b/GNUmakefile index ade50214068..d3c26ce8026 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -65,6 +65,7 @@ PROGS := \ date \ dd \ df \ + dir \ dircolors \ dirname \ echo \ @@ -118,6 +119,7 @@ PROGS := \ tsort \ unexpand \ uniq \ + vdir \ wc \ whoami \ yes diff --git a/src/uu/dir/Cargo.toml b/src/uu/dir/Cargo.toml new file mode 100644 index 00000000000..542abdc630e --- /dev/null +++ b/src/uu/dir/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "uu_dir" +version = "0.0.13" +authors = ["uutils developers"] +license = "MIT" +description = "shortcut to ls -C -b" + +homepage = "https://github.com/uutils/coreutils" +repository = "https://github.com/uutils/coreutils/tree/main/src/uu/ls" +keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"] +categories = ["command-line-utilities"] +edition = "2021" + +[lib] +path = "src/dir.rs" + +[dependencies] +clap = { version = "3.1", features = ["wrap_help", "cargo", "env"] } +uucore = { version = ">=0.0.8", package = "uucore", path = "../../uucore", features = ["entries", "fs"] } +selinux = { version="0.2", optional = true } +uu_ls = {path="../ls"} + +[[bin]] +name = "dir" +path = "src/main.rs" diff --git a/src/uu/dir/LICENSE b/src/uu/dir/LICENSE new file mode 120000 index 00000000000..5853aaea53b --- /dev/null +++ b/src/uu/dir/LICENSE @@ -0,0 +1 @@ +../../../LICENSE \ No newline at end of file diff --git a/src/uu/dir/src/dir.rs b/src/uu/dir/src/dir.rs new file mode 100644 index 00000000000..74907472668 --- /dev/null +++ b/src/uu/dir/src/dir.rs @@ -0,0 +1,70 @@ +// * This file is part of the uutils coreutils package. +// * +// * (c) gmnsii +// * +// * For the full copyright and license information, please view the LICENSE file +// * that was distributed with this source code. + +use clap::Command; +use std::path::Path; +use uu_ls::quoting_style::{Quotes, QuotingStyle}; +use uu_ls::{options, Config, Format}; +use uucore::error::UResult; + +#[uucore::main] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { + let command = uu_ls::uu_app(); + + let matches = command.get_matches_from(args); + + let mut default_quoting_style = false; + let mut default_format_style = false; + + // We check if any options on formatting or quoting style have been given. + // If not, we will use dir default formatting and quoting style options + + if !matches.is_present(options::QUOTING_STYLE) + && !matches.is_present(options::quoting::C) + && !matches.is_present(options::quoting::ESCAPE) + && !matches.is_present(options::quoting::LITERAL) + { + default_quoting_style = true; + } + if !matches.is_present(options::FORMAT) + && !matches.is_present(options::format::ACROSS) + && !matches.is_present(options::format::COLUMNS) + && !matches.is_present(options::format::COMMAS) + && !matches.is_present(options::format::LONG) + && !matches.is_present(options::format::LONG_NO_GROUP) + && !matches.is_present(options::format::LONG_NO_OWNER) + && !matches.is_present(options::format::LONG_NUMERIC_UID_GID) + && !matches.is_present(options::format::ONE_LINE) + { + default_format_style = true; + } + + let mut config = Config::from(&matches)?; + + if default_quoting_style { + config.quoting_style = QuotingStyle::C { + quotes: Quotes::None, + }; + } + if default_format_style { + config.format = Format::Columns; + } + + let locs = matches + .values_of_os(options::PATHS) + .map(|v| v.map(Path::new).collect()) + .unwrap_or_else(|| vec![Path::new(".")]); + + uu_ls::list(locs, &config) +} + +// To avoid code duplication, we reuse ls uu_app function which has the same +// arguments. However, coreutils won't compile if one of the utils is missing +// an uu_app function, so we need this dummy one. +pub fn uu_app<'a>() -> Command<'a> { + Command::new(uucore::util_name()) +} diff --git a/src/uu/dir/src/main.rs b/src/uu/dir/src/main.rs new file mode 100644 index 00000000000..c5b5b6363d8 --- /dev/null +++ b/src/uu/dir/src/main.rs @@ -0,0 +1 @@ +uucore::bin!(uu_dir); diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 7782830393b..a55f29e238d 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -13,7 +13,8 @@ extern crate uucore; #[macro_use] extern crate lazy_static; -mod quoting_style; +// dir and vdir also need access to the quoting_style module +pub mod quoting_style; use clap::{crate_version, Arg, Command}; use glob::Pattern; @@ -242,7 +243,7 @@ impl Display for LsError { } #[derive(PartialEq, Eq)] -enum Format { +pub enum Format { Columns, Long, OneLine, @@ -304,8 +305,9 @@ enum IndicatorStyle { Classify, } -struct Config { - format: Format, +pub struct Config { + // Dir and vdir needs access to this field + pub format: Format, files: Files, sort: Sort, recursive: bool, @@ -322,7 +324,8 @@ struct Config { alloc_size: bool, block_size: Option, width: u16, - quoting_style: QuotingStyle, + // Dir and vdir needs access to this field + pub quoting_style: QuotingStyle, indicator_style: IndicatorStyle, time_style: TimeStyle, context: bool, @@ -355,7 +358,7 @@ struct PaddingCollection { impl Config { #[allow(clippy::cognitive_complexity)] - fn from(options: &clap::ArgMatches) -> UResult { + pub fn from(options: &clap::ArgMatches) -> UResult { let context = options.is_present(options::CONTEXT); let (mut format, opt) = if let Some(format_) = options.value_of(options::FORMAT) { ( @@ -800,615 +803,611 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app<'a>() -> Command<'a> { Command::new(uucore::util_name()) .version(crate_version!()) - .override_usage(format_usage(USAGE)) - .about( - "By default, ls will list the files and contents of any directories on \ - the command line, expect that it will ignore files and directories \ - whose names start with '.'.", - ) - .infer_long_args(true) - .arg( - Arg::new(options::HELP) - .long(options::HELP) - .help("Print help information.") - ) - // Format arguments - .arg( - Arg::new(options::FORMAT) - .long(options::FORMAT) - .help("Set the display format.") - .takes_value(true) - .possible_values(&[ - "long", - "verbose", - "single-column", - "columns", - "vertical", - "across", - "horizontal", - "commas", - ]) - .hide_possible_values(true) - .require_equals(true) - .overrides_with_all(&[ - options::FORMAT, - options::format::COLUMNS, - options::format::LONG, - options::format::ACROSS, - options::format::COLUMNS, - ]), - ) - .arg( - Arg::new(options::format::COLUMNS) - .short('C') - .help("Display the files in columns.") - .overrides_with_all(&[ - options::FORMAT, - options::format::COLUMNS, - options::format::LONG, - options::format::ACROSS, - options::format::COLUMNS, - ]), - ) - .arg( - Arg::new(options::format::LONG) - .short('l') - .long(options::format::LONG) - .help("Display detailed information.") - .overrides_with_all(&[ - options::FORMAT, - options::format::COLUMNS, - options::format::LONG, - options::format::ACROSS, - options::format::COLUMNS, - ]), - ) - .arg( - Arg::new(options::format::ACROSS) - .short('x') - .help("List entries in rows instead of in columns.") - .overrides_with_all(&[ - options::FORMAT, - options::format::COLUMNS, - options::format::LONG, - options::format::ACROSS, - options::format::COLUMNS, - ]), - ) - .arg( - Arg::new(options::format::COMMAS) - .short('m') - .help("List entries separated by commas.") - .overrides_with_all(&[ - options::FORMAT, - options::format::COLUMNS, - options::format::LONG, - options::format::ACROSS, - options::format::COLUMNS, - ]), - ) - // The next four arguments do not override with the other format - // options, see the comment in Config::from for the reason. - // Ideally, they would use Arg::override_with, with their own name - // but that doesn't seem to work in all cases. Example: - // ls -1g1 - // even though `ls -11` and `ls -1 -g -1` work. - .arg( - Arg::new(options::format::ONE_LINE) - .short('1') - .help("List one file per line.") - .multiple_occurrences(true), - ) - .arg( - Arg::new(options::format::LONG_NO_GROUP) - .short('o') - .help( - "Long format without group information. \ - Identical to --format=long with --no-group.", - ) - .multiple_occurrences(true), - ) - .arg( - Arg::new(options::format::LONG_NO_OWNER) - .short('g') - .help("Long format without owner information.") - .multiple_occurrences(true), - ) - .arg( - Arg::new(options::format::LONG_NUMERIC_UID_GID) - .short('n') - .long(options::format::LONG_NUMERIC_UID_GID) - .help("-l with numeric UIDs and GIDs.") - .multiple_occurrences(true), - ) - // Quoting style - .arg( - Arg::new(options::QUOTING_STYLE) - .long(options::QUOTING_STYLE) - .takes_value(true) - .help("Set quoting style.") - .possible_values(&[ - "literal", - "shell", - "shell-always", - "shell-escape", - "shell-escape-always", - "c", - "escape", - ]) - .overrides_with_all(&[ - options::QUOTING_STYLE, - options::quoting::LITERAL, - options::quoting::ESCAPE, - options::quoting::C, - ]), - ) - .arg( - Arg::new(options::quoting::LITERAL) - .short('N') - .long(options::quoting::LITERAL) - .help("Use literal quoting style. Equivalent to `--quoting-style=literal`") - .overrides_with_all(&[ - options::QUOTING_STYLE, - options::quoting::LITERAL, - options::quoting::ESCAPE, - options::quoting::C, - ]), - ) - .arg( - Arg::new(options::quoting::ESCAPE) - .short('b') - .long(options::quoting::ESCAPE) - .help("Use escape quoting style. Equivalent to `--quoting-style=escape`") - .overrides_with_all(&[ - options::QUOTING_STYLE, - options::quoting::LITERAL, - options::quoting::ESCAPE, - options::quoting::C, - ]), - ) - .arg( - Arg::new(options::quoting::C) - .short('Q') - .long(options::quoting::C) - .help("Use C quoting style. Equivalent to `--quoting-style=c`") - .overrides_with_all(&[ - options::QUOTING_STYLE, - options::quoting::LITERAL, - options::quoting::ESCAPE, - options::quoting::C, - ]), - ) - // Control characters - .arg( - Arg::new(options::HIDE_CONTROL_CHARS) - .short('q') - .long(options::HIDE_CONTROL_CHARS) - .help("Replace control characters with '?' if they are not escaped.") - .overrides_with_all(&[options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]), - ) - .arg( - Arg::new(options::SHOW_CONTROL_CHARS) - .long(options::SHOW_CONTROL_CHARS) - .help("Show control characters 'as is' if they are not escaped.") - .overrides_with_all(&[options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]), - ) - // Time arguments - .arg( - Arg::new(options::TIME) - .long(options::TIME) - .help( - "Show time in :\n\ - \taccess time (-u): atime, access, use;\n\ - \tchange time (-t): ctime, status.\n\ - \tbirth time: birth, creation;", - ) - .value_name("field") - .takes_value(true) - .possible_values(&[ - "atime", "access", "use", "ctime", "status", "birth", "creation", - ]) - .hide_possible_values(true) - .require_equals(true) - .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), - ) - .arg( - Arg::new(options::time::CHANGE) - .short('c') - .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 \ - explicitly sorting by time (--sort=time or -t) or when not using a long listing \ - format, sort according to the status change time.", - ) - .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), - ) - .arg( - Arg::new(options::time::ACCESS) - .short('u') - .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 \ - (--sort=time or -t) or when not using a long listing format, sort according to the \ - access time.", - ) - .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), - ) - // Hide and ignore - .arg( - Arg::new(options::HIDE) - .long(options::HIDE) - .takes_value(true) - .multiple_occurrences(true) - .value_name("PATTERN") - .help( - "do not list implied entries matching shell PATTERN (overridden by -a or -A)", - ), - ) - .arg( - Arg::new(options::IGNORE) - .short('I') - .long(options::IGNORE) - .takes_value(true) - .multiple_occurrences(true) - .value_name("PATTERN") - .help("do not list implied entries matching shell PATTERN"), - ) - .arg( - Arg::new(options::IGNORE_BACKUPS) - .short('B') - .long(options::IGNORE_BACKUPS) - .help("Ignore entries which end with ~."), - ) - // Sort arguments - .arg( - Arg::new(options::SORT) - .long(options::SORT) - .help("Sort by : name, none (-U), time (-t), size (-S) or extension (-X)") - .value_name("field") - .takes_value(true) - .possible_values(&["name", "none", "time", "size", "version", "extension"]) - .require_equals(true) - .overrides_with_all(&[ - options::SORT, - options::sort::SIZE, - options::sort::TIME, - options::sort::NONE, - options::sort::VERSION, - options::sort::EXTENSION, - ]), - ) - .arg( - Arg::new(options::sort::SIZE) - .short('S') - .help("Sort by file size, largest first.") - .overrides_with_all(&[ - options::SORT, - options::sort::SIZE, - options::sort::TIME, - options::sort::NONE, - options::sort::VERSION, - options::sort::EXTENSION, - ]), - ) - .arg( - Arg::new(options::sort::TIME) - .short('t') - .help("Sort by modification time (the 'mtime' in the inode), newest first.") - .overrides_with_all(&[ - options::SORT, - options::sort::SIZE, - options::sort::TIME, - options::sort::NONE, - options::sort::VERSION, - options::sort::EXTENSION, - ]), - ) - .arg( - Arg::new(options::sort::VERSION) - .short('v') - .help("Natural sort of (version) numbers in the filenames.") - .overrides_with_all(&[ - options::SORT, - options::sort::SIZE, - options::sort::TIME, - options::sort::NONE, - options::sort::VERSION, - options::sort::EXTENSION, - ]), - ) - .arg( - Arg::new(options::sort::EXTENSION) - .short('X') - .help("Sort alphabetically by entry extension.") - .overrides_with_all(&[ - options::SORT, - options::sort::SIZE, - options::sort::TIME, - options::sort::NONE, - options::sort::VERSION, - options::sort::EXTENSION, - ]), - ) - .arg( - Arg::new(options::sort::NONE) - .short('U') - .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, \ - since not doing any sorting can be noticeably faster.", - ) - .overrides_with_all(&[ - options::SORT, - options::sort::SIZE, - options::sort::TIME, - options::sort::NONE, - options::sort::VERSION, - options::sort::EXTENSION, - ]), - ) - // Dereferencing - .arg( - Arg::new(options::dereference::ALL) - .short('L') - .long(options::dereference::ALL) - .help( - "When showing file information for a symbolic link, show information for the \ - file the link references rather than the link itself.", - ) - .overrides_with_all(&[ - options::dereference::ALL, - options::dereference::DIR_ARGS, - options::dereference::ARGS, - ]), - ) - .arg( - Arg::new(options::dereference::DIR_ARGS) - .long(options::dereference::DIR_ARGS) - .help( - "Do not dereference symlinks except when they link to directories and are \ - given as command line arguments.", - ) - .overrides_with_all(&[ - options::dereference::ALL, - options::dereference::DIR_ARGS, - options::dereference::ARGS, - ]), - ) - .arg( - Arg::new(options::dereference::ARGS) - .short('H') - .long(options::dereference::ARGS) - .help("Do not dereference symlinks except when given as command line arguments.") - .overrides_with_all(&[ - options::dereference::ALL, - options::dereference::DIR_ARGS, - options::dereference::ARGS, - ]), - ) - // Long format options - .arg( - Arg::new(options::NO_GROUP) - .long(options::NO_GROUP) - .short('G') - .help("Do not show group in long format."), - ) - .arg(Arg::new(options::AUTHOR).long(options::AUTHOR).help( - "Show author in long format. \ - On the supported platforms, the author always matches the file owner.", - )) - // Other Flags - .arg( - Arg::new(options::files::ALL) - .short('a') - .long(options::files::ALL) - // Overrides -A (as the order matters) - .overrides_with(options::files::ALMOST_ALL) - .multiple_occurrences(true) - .help("Do not ignore hidden files (files with names that start with '.')."), - ) - .arg( - Arg::new(options::files::ALMOST_ALL) - .short('A') - .long(options::files::ALMOST_ALL) - // Overrides -a (as the order matters) - .overrides_with(options::files::ALL) - .multiple_occurrences(true) - .help( - "In a directory, do not ignore all file names that start with '.', \ -only ignore '.' and '..'.", - ), - ) - .arg( - Arg::new(options::DIRECTORY) - .short('d') - .long(options::DIRECTORY) - .help( - "Only list the names of directories, rather than listing directory contents. \ - This will not follow symbolic links unless one of `--dereference-command-line \ - (-H)`, `--dereference (-L)`, or `--dereference-command-line-symlink-to-dir` is \ - specified.", - ), - ) - .arg( - Arg::new(options::size::HUMAN_READABLE) - .short('h') - .long(options::size::HUMAN_READABLE) - .help("Print human readable file sizes (e.g. 1K 234M 56G).") - .overrides_with(options::size::SI), - ) - .arg( - Arg::new(options::size::KIBIBYTES) - .short('k') - .long(options::size::KIBIBYTES) - .help("default to 1024-byte blocks for file system usage; used only with -s and per directory totals"), - ) - .arg( - Arg::new(options::size::SI) - .long(options::size::SI) - .help("Print human readable file sizes using powers of 1000 instead of 1024."), - ) - .arg( - Arg::new(options::size::BLOCK_SIZE) - .long(options::size::BLOCK_SIZE) - .takes_value(true) - .require_equals(true) - .value_name("BLOCK_SIZE") - .help("scale sizes by BLOCK_SIZE when printing them"), - ) - .arg( - Arg::new(options::INODE) - .short('i') - .long(options::INODE) - .help("print the index number of each file"), - ) - .arg( - Arg::new(options::REVERSE) - .short('r') - .long(options::REVERSE) - .help( - "Reverse whatever the sorting method is e.g., list files in reverse \ - alphabetical order, youngest first, smallest first, or whatever.", - ), - ) - .arg( - Arg::new(options::RECURSIVE) - .short('R') - .long(options::RECURSIVE) - .help("List the contents of all directories recursively."), - ) - .arg( - Arg::new(options::WIDTH) - .long(options::WIDTH) - .short('w') - .help("Assume that the terminal is COLS columns wide.") - .value_name("COLS") - .takes_value(true), - ) - .arg( - Arg::new(options::size::ALLOCATION_SIZE) - .short('s') - .long(options::size::ALLOCATION_SIZE) - .help("print the allocated size of each file, in blocks"), - ) - .arg( - Arg::new(options::COLOR) - .long(options::COLOR) - .help("Color output based on file type.") - .takes_value(true) - .possible_values(&[ - "always", "yes", "force", "auto", "tty", "if-tty", "never", "no", "none", - ]) - .require_equals(true) - .min_values(0), - ) - .arg( - Arg::new(options::INDICATOR_STYLE) - .long(options::INDICATOR_STYLE) - .help( - "Append indicator with style WORD to entry names: \ - none (default), slash (-p), file-type (--file-type), classify (-F)", - ) - .takes_value(true) - .possible_values(&["none", "slash", "file-type", "classify"]) - .overrides_with_all(&[ - options::indicator_style::FILE_TYPE, - options::indicator_style::SLASH, - options::indicator_style::CLASSIFY, - options::INDICATOR_STYLE, - ]), - ) - .arg( - // The --classify flag can take an optional when argument to - // control its behavior from version 9 of GNU coreutils. - // There is currently an inconsistency where GNU coreutils allows only - // the long form of the flag to take the argument while we allow it - // for both the long and short form of the flag. - Arg::new(options::indicator_style::CLASSIFY) - .short('F') - .long(options::indicator_style::CLASSIFY) - .help( - "Append a character to each file name indicating the file type. Also, for \ - regular files that are executable, append '*'. The file type indicators are \ - '/' for directories, '@' for symbolic links, '|' for FIFOs, '=' for sockets, \ - '>' for doors, and nothing for regular files. when may be omitted, or one of:\n\ - \tnone - Do not classify. This is the default.\n\ - \tauto - Only classify if standard output is a terminal.\n\ - \talways - Always classify.\n\ - Specifying --classify and no when is equivalent to --classify=always. This will not follow\ - symbolic links listed on the command line unless the --dereference-command-line (-H),\ - --dereference (-L), or --dereference-command-line-symlink-to-dir options are specified.", - ) - .takes_value(true) - .value_name("when") - .possible_values(&[ - "always", "yes", "force", "auto", "tty", "if-tty", "never", "no", "none", - ]) - .default_missing_value("always") - .require_equals(true) - .min_values(0) - .overrides_with_all(&[ - options::indicator_style::FILE_TYPE, - options::indicator_style::SLASH, - options::indicator_style::CLASSIFY, - options::INDICATOR_STYLE, - ]), - ) - .arg( - Arg::new(options::indicator_style::FILE_TYPE) - .long(options::indicator_style::FILE_TYPE) - .help("Same as --classify, but do not append '*'") - .overrides_with_all(&[ - options::indicator_style::FILE_TYPE, - options::indicator_style::SLASH, - options::indicator_style::CLASSIFY, - options::INDICATOR_STYLE, - ]), - ) - .arg( - Arg::new(options::indicator_style::SLASH) - .short('p') - .help("Append / indicator to directories.") - .overrides_with_all(&[ - options::indicator_style::FILE_TYPE, - options::indicator_style::SLASH, - options::indicator_style::CLASSIFY, - options::INDICATOR_STYLE, - ]), - ) - .arg( - //This still needs support for posix-*, +FORMAT - Arg::new(options::TIME_STYLE) - .long(options::TIME_STYLE) - .help("time/date format with -l; see TIME_STYLE below") - .value_name("TIME_STYLE") - .env("TIME_STYLE") - .possible_values(&["full-iso", "long-iso", "iso", "locale"]) - .overrides_with_all(&[options::TIME_STYLE]), - ) - .arg( - Arg::new(options::FULL_TIME) - .long(options::FULL_TIME) - .overrides_with(options::FULL_TIME) - .help("like -l --time-style=full-iso"), - ) - .arg( - Arg::new(options::CONTEXT) - .short('Z') - .long(options::CONTEXT) - .help(CONTEXT_HELP_TEXT), - ) - // Positional arguments - .arg( - Arg::new(options::PATHS) - .multiple_occurrences(true) - .takes_value(true) - .allow_invalid_utf8(true), - ) - .after_help( - "The TIME_STYLE argument can be full-iso, long-iso, iso. \ - Also the TIME_STYLE environment variable sets the default style to use.", - ) + .override_usage(format_usage(USAGE)) + .about("List directory contents. Ignore files and directories starting with a '.' by default") + .infer_long_args(true) + .arg( + Arg::new(options::HELP) + .long(options::HELP) + .help("Print help information.") + ) + // Format arguments + .arg( + Arg::new(options::FORMAT) + .long(options::FORMAT) + .help("Set the display format.") + .takes_value(true) + .possible_values(&[ + "long", + "verbose", + "single-column", + "columns", + "vertical", + "across", + "horizontal", + "commas", + ]) + .hide_possible_values(true) + .require_equals(true) + .overrides_with_all(&[ + options::FORMAT, + options::format::COLUMNS, + options::format::LONG, + options::format::ACROSS, + options::format::COLUMNS, + ]), + ) + .arg( + Arg::new(options::format::COLUMNS) + .short('C') + .help("Display the files in columns.") + .overrides_with_all(&[ + options::FORMAT, + options::format::COLUMNS, + options::format::LONG, + options::format::ACROSS, + options::format::COLUMNS, + ]), + ) + .arg( + Arg::new(options::format::LONG) + .short('l') + .long(options::format::LONG) + .help("Display detailed information.") + .overrides_with_all(&[ + options::FORMAT, + options::format::COLUMNS, + options::format::LONG, + options::format::ACROSS, + options::format::COLUMNS, + ]), + ) + .arg( + Arg::new(options::format::ACROSS) + .short('x') + .help("List entries in rows instead of in columns.") + .overrides_with_all(&[ + options::FORMAT, + options::format::COLUMNS, + options::format::LONG, + options::format::ACROSS, + options::format::COLUMNS, + ]), + ) + .arg( + Arg::new(options::format::COMMAS) + .short('m') + .help("List entries separated by commas.") + .overrides_with_all(&[ + options::FORMAT, + options::format::COLUMNS, + options::format::LONG, + options::format::ACROSS, + options::format::COLUMNS, + ]), + ) + // The next four arguments do not override with the other format + // options, see the comment in Config::from for the reason. + // Ideally, they would use Arg::override_with, with their own name + // but that doesn't seem to work in all cases. Example: + // ls -1g1 + // even though `ls -11` and `ls -1 -g -1` work. + .arg( + Arg::new(options::format::ONE_LINE) + .short('1') + .help("List one file per line.") + .multiple_occurrences(true), + ) + .arg( + Arg::new(options::format::LONG_NO_GROUP) + .short('o') + .help( + "Long format without group information. \ + Identical to --format=long with --no-group.", + ) + .multiple_occurrences(true), + ) + .arg( + Arg::new(options::format::LONG_NO_OWNER) + .short('g') + .help("Long format without owner information.") + .multiple_occurrences(true), + ) + .arg( + Arg::new(options::format::LONG_NUMERIC_UID_GID) + .short('n') + .long(options::format::LONG_NUMERIC_UID_GID) + .help("-l with numeric UIDs and GIDs.") + .multiple_occurrences(true), + ) + // Quoting style + .arg( + Arg::new(options::QUOTING_STYLE) + .long(options::QUOTING_STYLE) + .takes_value(true) + .help("Set quoting style.") + .possible_values(&[ + "literal", + "shell", + "shell-always", + "shell-escape", + "shell-escape-always", + "c", + "escape", + ]) + .overrides_with_all(&[ + options::QUOTING_STYLE, + options::quoting::LITERAL, + options::quoting::ESCAPE, + options::quoting::C, + ]), + ) + .arg( + Arg::new(options::quoting::LITERAL) + .short('N') + .long(options::quoting::LITERAL) + .help("Use literal quoting style. Equivalent to `--quoting-style=literal`") + .overrides_with_all(&[ + options::QUOTING_STYLE, + options::quoting::LITERAL, + options::quoting::ESCAPE, + options::quoting::C, + ]), + ) + .arg( + Arg::new(options::quoting::ESCAPE) + .short('b') + .long(options::quoting::ESCAPE) + .help("Use escape quoting style. Equivalent to `--quoting-style=escape`") + .overrides_with_all(&[ + options::QUOTING_STYLE, + options::quoting::LITERAL, + options::quoting::ESCAPE, + options::quoting::C, + ]), + ) + .arg( + Arg::new(options::quoting::C) + .short('Q') + .long(options::quoting::C) + .help("Use C quoting style. Equivalent to `--quoting-style=c`") + .overrides_with_all(&[ + options::QUOTING_STYLE, + options::quoting::LITERAL, + options::quoting::ESCAPE, + options::quoting::C, + ]), + ) + // Control characters + .arg( + Arg::new(options::HIDE_CONTROL_CHARS) + .short('q') + .long(options::HIDE_CONTROL_CHARS) + .help("Replace control characters with '?' if they are not escaped.") + .overrides_with_all(&[options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]), + ) + .arg( + Arg::new(options::SHOW_CONTROL_CHARS) + .long(options::SHOW_CONTROL_CHARS) + .help("Show control characters 'as is' if they are not escaped.") + .overrides_with_all(&[options::HIDE_CONTROL_CHARS, options::SHOW_CONTROL_CHARS]), + ) + // Time arguments + .arg( + Arg::new(options::TIME) + .long(options::TIME) + .help( + "Show time in :\n\ + \taccess time (-u): atime, access, use;\n\ + \tchange time (-t): ctime, status.\n\ + \tbirth time: birth, creation;", + ) + .value_name("field") + .takes_value(true) + .possible_values(&[ + "atime", "access", "use", "ctime", "status", "birth", "creation", + ]) + .hide_possible_values(true) + .require_equals(true) + .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), + ) + .arg( + Arg::new(options::time::CHANGE) + .short('c') + .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 \ + explicitly sorting by time (--sort=time or -t) or when not using a long listing \ + format, sort according to the status change time.", + ) + .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), + ) + .arg( + Arg::new(options::time::ACCESS) + .short('u') + .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 \ + (--sort=time or -t) or when not using a long listing format, sort according to the \ + access time.", + ) + .overrides_with_all(&[options::TIME, options::time::ACCESS, options::time::CHANGE]), + ) + // Hide and ignore + .arg( + Arg::new(options::HIDE) + .long(options::HIDE) + .takes_value(true) + .multiple_occurrences(true) + .value_name("PATTERN") + .help( + "do not list implied entries matching shell PATTERN (overridden by -a or -A)", + ), + ) + .arg( + Arg::new(options::IGNORE) + .short('I') + .long(options::IGNORE) + .takes_value(true) + .multiple_occurrences(true) + .value_name("PATTERN") + .help("do not list implied entries matching shell PATTERN"), + ) + .arg( + Arg::new(options::IGNORE_BACKUPS) + .short('B') + .long(options::IGNORE_BACKUPS) + .help("Ignore entries which end with ~."), + ) + // Sort arguments + .arg( + Arg::new(options::SORT) + .long(options::SORT) + .help("Sort by : name, none (-U), time (-t), size (-S) or extension (-X)") + .value_name("field") + .takes_value(true) + .possible_values(&["name", "none", "time", "size", "version", "extension"]) + .require_equals(true) + .overrides_with_all(&[ + options::SORT, + options::sort::SIZE, + options::sort::TIME, + options::sort::NONE, + options::sort::VERSION, + options::sort::EXTENSION, + ]), + ) + .arg( + Arg::new(options::sort::SIZE) + .short('S') + .help("Sort by file size, largest first.") + .overrides_with_all(&[ + options::SORT, + options::sort::SIZE, + options::sort::TIME, + options::sort::NONE, + options::sort::VERSION, + options::sort::EXTENSION, + ]), + ) + .arg( + Arg::new(options::sort::TIME) + .short('t') + .help("Sort by modification time (the 'mtime' in the inode), newest first.") + .overrides_with_all(&[ + options::SORT, + options::sort::SIZE, + options::sort::TIME, + options::sort::NONE, + options::sort::VERSION, + options::sort::EXTENSION, + ]), + ) + .arg( + Arg::new(options::sort::VERSION) + .short('v') + .help("Natural sort of (version) numbers in the filenames.") + .overrides_with_all(&[ + options::SORT, + options::sort::SIZE, + options::sort::TIME, + options::sort::NONE, + options::sort::VERSION, + options::sort::EXTENSION, + ]), + ) + .arg( + Arg::new(options::sort::EXTENSION) + .short('X') + .help("Sort alphabetically by entry extension.") + .overrides_with_all(&[ + options::SORT, + options::sort::SIZE, + options::sort::TIME, + options::sort::NONE, + options::sort::VERSION, + options::sort::EXTENSION, + ]), + ) + .arg( + Arg::new(options::sort::NONE) + .short('U') + .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, \ + since not doing any sorting can be noticeably faster.", + ) + .overrides_with_all(&[ + options::SORT, + options::sort::SIZE, + options::sort::TIME, + options::sort::NONE, + options::sort::VERSION, + options::sort::EXTENSION, + ]), + ) + // Dereferencing + .arg( + Arg::new(options::dereference::ALL) + .short('L') + .long(options::dereference::ALL) + .help( + "When showing file information for a symbolic link, show information for the \ + file the link references rather than the link itself.", + ) + .overrides_with_all(&[ + options::dereference::ALL, + options::dereference::DIR_ARGS, + options::dereference::ARGS, + ]), + ) + .arg( + Arg::new(options::dereference::DIR_ARGS) + .long(options::dereference::DIR_ARGS) + .help( + "Do not dereference symlinks except when they link to directories and are \ + given as command line arguments.", + ) + .overrides_with_all(&[ + options::dereference::ALL, + options::dereference::DIR_ARGS, + options::dereference::ARGS, + ]), + ) + .arg( + Arg::new(options::dereference::ARGS) + .short('H') + .long(options::dereference::ARGS) + .help("Do not dereference symlinks except when given as command line arguments.") + .overrides_with_all(&[ + options::dereference::ALL, + options::dereference::DIR_ARGS, + options::dereference::ARGS, + ]), + ) + // Long format options + .arg( + Arg::new(options::NO_GROUP) + .long(options::NO_GROUP) + .short('G') + .help("Do not show group in long format."), + ) + .arg(Arg::new(options::AUTHOR).long(options::AUTHOR).help( + "Show author in long format. \ + On the supported platforms, the author always matches the file owner.", + )) + // Other Flags + .arg( + Arg::new(options::files::ALL) + .short('a') + .long(options::files::ALL) + // Overrides -A (as the order matters) + .overrides_with(options::files::ALMOST_ALL) + .multiple_occurrences(true) + .help("Do not ignore hidden files (files with names that start with '.')."), + ) + .arg( + Arg::new(options::files::ALMOST_ALL) + .short('A') + .long(options::files::ALMOST_ALL) + // Overrides -a (as the order matters) + .overrides_with(options::files::ALL) + .multiple_occurrences(true) + .help( + "In a directory, do not ignore all file names that start with '.', \ + only ignore '.' and '..'.", + ), + ) + .arg( + Arg::new(options::DIRECTORY) + .short('d') + .long(options::DIRECTORY) + .help( + "Only list the names of directories, rather than listing directory contents. \ + This will not follow symbolic links unless one of `--dereference-command-line \ + (-H)`, `--dereference (-L)`, or `--dereference-command-line-symlink-to-dir` is \ + specified.", + ), + ) + .arg( + Arg::new(options::size::HUMAN_READABLE) + .short('h') + .long(options::size::HUMAN_READABLE) + .help("Print human readable file sizes (e.g. 1K 234M 56G).") + .overrides_with(options::size::SI), + ) + .arg( + Arg::new(options::size::KIBIBYTES) + .short('k') + .long(options::size::KIBIBYTES) + .help("default to 1024-byte blocks for file system usage; used only with -s and per directory totals"), + ) + .arg( + Arg::new(options::size::SI) + .long(options::size::SI) + .help("Print human readable file sizes using powers of 1000 instead of 1024."), + ) + .arg( + Arg::new(options::size::BLOCK_SIZE) + .long(options::size::BLOCK_SIZE) + .takes_value(true) + .require_equals(true) + .value_name("BLOCK_SIZE") + .help("scale sizes by BLOCK_SIZE when printing them"), + ) + .arg( + Arg::new(options::INODE) + .short('i') + .long(options::INODE) + .help("print the index number of each file"), + ) + .arg( + Arg::new(options::REVERSE) + .short('r') + .long(options::REVERSE) + .help( + "Reverse whatever the sorting method is e.g., list files in reverse \ + alphabetical order, youngest first, smallest first, or whatever.", + ), + ) + .arg( + Arg::new(options::RECURSIVE) + .short('R') + .long(options::RECURSIVE) + .help("List the contents of all directories recursively."), + ) + .arg( + Arg::new(options::WIDTH) + .long(options::WIDTH) + .short('w') + .help("Assume that the terminal is COLS columns wide.") + .value_name("COLS") + .takes_value(true), + ) + .arg( + Arg::new(options::size::ALLOCATION_SIZE) + .short('s') + .long(options::size::ALLOCATION_SIZE) + .help("print the allocated size of each file, in blocks"), + ) + .arg( + Arg::new(options::COLOR) + .long(options::COLOR) + .help("Color output based on file type.") + .takes_value(true) + .possible_values(&[ + "always", "yes", "force", "auto", "tty", "if-tty", "never", "no", "none", + ]) + .require_equals(true) + .min_values(0), + ) + .arg( + Arg::new(options::INDICATOR_STYLE) + .long(options::INDICATOR_STYLE) + .help( + "Append indicator with style WORD to entry names: \ + none (default), slash (-p), file-type (--file-type), classify (-F)", + ) + .takes_value(true) + .possible_values(&["none", "slash", "file-type", "classify"]) + .overrides_with_all(&[ + options::indicator_style::FILE_TYPE, + options::indicator_style::SLASH, + options::indicator_style::CLASSIFY, + options::INDICATOR_STYLE, + ]), + ) + .arg( + // The --classify flag can take an optional when argument to + // control its behavior from version 9 of GNU coreutils. + // There is currently an inconsistency where GNU coreutils allows only + // the long form of the flag to take the argument while we allow it + // for both the long and short form of the flag. + Arg::new(options::indicator_style::CLASSIFY) + .short('F') + .long(options::indicator_style::CLASSIFY) + .help( + "Append a character to each file name indicating the file type. Also, for \ + regular files that are executable, append '*'. The file type indicators are \ + '/' for directories, '@' for symbolic links, '|' for FIFOs, '=' for sockets, \ + '>' for doors, and nothing for regular files. when may be omitted, or one of:\n\ + \tnone - Do not classify. This is the default.\n\ + \tauto - Only classify if standard output is a terminal.\n\ + \talways - Always classify.\n\ + Specifying --classify and no when is equivalent to --classify=always. This will not follow\ + symbolic links listed on the command line unless the --dereference-command-line (-H),\ + --dereference (-L), or --dereference-command-line-symlink-to-dir options are specified.", + ) + .takes_value(true) + .value_name("when") + .possible_values(&[ + "always", "yes", "force", "auto", "tty", "if-tty", "never", "no", "none", + ]) + .default_missing_value("always") + .require_equals(true) + .min_values(0) + .overrides_with_all(&[ + options::indicator_style::FILE_TYPE, + options::indicator_style::SLASH, + options::indicator_style::CLASSIFY, + options::INDICATOR_STYLE, + ]), + ) + .arg( + Arg::new(options::indicator_style::FILE_TYPE) + .long(options::indicator_style::FILE_TYPE) + .help("Same as --classify, but do not append '*'") + .overrides_with_all(&[ + options::indicator_style::FILE_TYPE, + options::indicator_style::SLASH, + options::indicator_style::CLASSIFY, + options::INDICATOR_STYLE, + ]), + ) + .arg( + Arg::new(options::indicator_style::SLASH) + .short('p') + .help("Append / indicator to directories.") + .overrides_with_all(&[ + options::indicator_style::FILE_TYPE, + options::indicator_style::SLASH, + options::indicator_style::CLASSIFY, + options::INDICATOR_STYLE, + ]), + ) + .arg( + //This still needs support for posix-*, +FORMAT + Arg::new(options::TIME_STYLE) + .long(options::TIME_STYLE) + .help("time/date format with -l; see TIME_STYLE below") + .value_name("TIME_STYLE") + .env("TIME_STYLE") + .possible_values(&["full-iso", "long-iso", "iso", "locale"]) + .overrides_with_all(&[options::TIME_STYLE]), + ) + .arg( + Arg::new(options::FULL_TIME) + .long(options::FULL_TIME) + .overrides_with(options::FULL_TIME) + .help("like -l --time-style=full-iso"), + ) + .arg( + Arg::new(options::CONTEXT) + .short('Z') + .long(options::CONTEXT) + .help(CONTEXT_HELP_TEXT), + ) + // Positional arguments + .arg( + Arg::new(options::PATHS) + .multiple_occurrences(true) + .takes_value(true) + .allow_invalid_utf8(true), + ) + .after_help( + "The TIME_STYLE argument can be full-iso, long-iso, iso. \ + Also the TIME_STYLE environment variable sets the default style to use.", + ) } /// Represents a Path along with it's associated data. @@ -1543,7 +1542,7 @@ impl PathData { } } -fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { +pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { let mut files = Vec::::new(); let mut dirs = Vec::::new(); let mut out = BufWriter::new(stdout()); diff --git a/src/uu/ls/src/quoting_style.rs b/src/uu/ls/src/quoting_style.rs index 4900dc566b7..9ff68927302 100644 --- a/src/uu/ls/src/quoting_style.rs +++ b/src/uu/ls/src/quoting_style.rs @@ -6,7 +6,7 @@ use std::ffi::OsStr; const SPECIAL_SHELL_CHARS_START: &[char] = &['~', '#']; const SPECIAL_SHELL_CHARS: &str = "`$&*()|[]{};\\'\"<>?! "; -pub(super) enum QuotingStyle { +pub enum QuotingStyle { Shell { escape: bool, always_quote: bool, @@ -21,7 +21,7 @@ pub(super) enum QuotingStyle { } #[derive(Clone, Copy)] -pub(super) enum Quotes { +pub enum Quotes { None, Single, Double, diff --git a/src/uu/vdir/Cargo.toml b/src/uu/vdir/Cargo.toml new file mode 100644 index 00000000000..10dc07a255d --- /dev/null +++ b/src/uu/vdir/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "uu_vdir" +version = "0.0.13" +authors = ["uutils developers"] +license = "MIT" +description = "shortcut to ls -l -b" + +homepage = "https://github.com/uutils/coreutils" +repository = "https://github.com/uutils/coreutils/tree/main/src/uu/ls" +keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"] +categories = ["command-line-utilities"] +edition = "2021" + +[lib] +path = "src/vdir.rs" + +[dependencies] +clap = { version = "3.1", features = ["wrap_help", "cargo", "env"] } +uucore = { version = ">=0.0.8", package = "uucore", path = "../../uucore", features = ["entries", "fs"] } +selinux = { version="0.2", optional = true } +uu_ls = {path="../ls"} + +[[bin]] +name = "vdir" +path = "src/main.rs" diff --git a/src/uu/vdir/LICENSE b/src/uu/vdir/LICENSE new file mode 120000 index 00000000000..5853aaea53b --- /dev/null +++ b/src/uu/vdir/LICENSE @@ -0,0 +1 @@ +../../../LICENSE \ No newline at end of file diff --git a/src/uu/vdir/src/main.rs b/src/uu/vdir/src/main.rs new file mode 100644 index 00000000000..9d9ba9de0c3 --- /dev/null +++ b/src/uu/vdir/src/main.rs @@ -0,0 +1 @@ +uucore::bin!(uu_vdir); diff --git a/src/uu/vdir/src/vdir.rs b/src/uu/vdir/src/vdir.rs new file mode 100644 index 00000000000..b2af0b332ad --- /dev/null +++ b/src/uu/vdir/src/vdir.rs @@ -0,0 +1,68 @@ +// * This file is part of the uutils coreutils package. +// * +// * (c) gmnsii +// * +// * For the full copyright and license information, please view the LICENSE file +// * that was distributed with this source code. + +use clap::Command; +use std::path::Path; +use uu_ls::quoting_style::{Quotes, QuotingStyle}; +use uu_ls::{options, Config, Format}; +use uucore::error::UResult; + +#[uucore::main] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { + let command = uu_ls::uu_app(); + let matches = command.get_matches_from(args); + + let mut default_quoting_style = false; + let mut default_format_style = false; + + // We check if any options on formatting or quoting style have been given. + // If not, we will use dir default formatting and quoting style options + + if !matches.is_present(options::QUOTING_STYLE) + && !matches.is_present(options::quoting::C) + && !matches.is_present(options::quoting::ESCAPE) + && !matches.is_present(options::quoting::LITERAL) + { + default_quoting_style = true; + } + if !matches.is_present(options::FORMAT) + && !matches.is_present(options::format::ACROSS) + && !matches.is_present(options::format::COLUMNS) + && !matches.is_present(options::format::COMMAS) + && !matches.is_present(options::format::LONG) + && !matches.is_present(options::format::LONG_NO_GROUP) + && !matches.is_present(options::format::LONG_NO_OWNER) + && !matches.is_present(options::format::LONG_NUMERIC_UID_GID) + && !matches.is_present(options::format::ONE_LINE) + { + default_format_style = true; + } + + let mut config = Config::from(&matches)?; + + if default_quoting_style { + config.quoting_style = QuotingStyle::C { + quotes: Quotes::None, + }; + } + if default_format_style { + config.format = Format::Long; + } + + let locs = matches + .values_of_os(options::PATHS) + .map(|v| v.map(Path::new).collect()) + .unwrap_or_else(|| vec![Path::new(".")]); + uu_ls::list(locs, &config) +} + +// To avoid code duplication, we reuse ls uu_app function which has the same +// arguments. However, coreutils won't compile if one of the utils is missing +// an uu_app function, so we need this dummy one. +pub fn uu_app<'a>() -> Command<'a> { + Command::new(uucore::util_name()) +} diff --git a/tests/by-util/test_dir.rs b/tests/by-util/test_dir.rs new file mode 100644 index 00000000000..3ec416bb2ac --- /dev/null +++ b/tests/by-util/test_dir.rs @@ -0,0 +1,55 @@ +#[cfg(not(windows))] +extern crate libc; +extern crate regex; +#[cfg(not(windows))] +extern crate tempfile; +#[cfg(unix)] +extern crate unix_socket; + +use self::regex::Regex; +use crate::common::util::*; + +/* + * As dir use the same functions than ls, we don't have to retest them here. + * We just test the default and the long output +*/ + +#[test] +fn test_dir() { + new_ucmd!().succeeds(); +} + +#[test] +fn test_default_output() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("some-dir1"); + at.touch("some-file1"); + + scene.ucmd().succeeds().stdout_contains("some-file1"); + + scene + .ucmd() + .succeeds() + .stdout_does_not_match(&Regex::new("[rwx][^some-file1]").unwrap()); +} + +#[test] +fn test_long_output() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("some-dir1"); + at.touch("some-file1"); + + scene + .ucmd() + .arg("-l") + .succeeds() + .stdout_contains("some-file1"); + + scene + .ucmd() + .arg("-l") + .succeeds() + .stdout_matches(&Regex::new("[rwx][^some-file1]").unwrap()); +} diff --git a/tests/by-util/test_vdir.rs b/tests/by-util/test_vdir.rs new file mode 100644 index 00000000000..01c54009595 --- /dev/null +++ b/tests/by-util/test_vdir.rs @@ -0,0 +1,55 @@ +#[cfg(not(windows))] +extern crate libc; +extern crate regex; +#[cfg(not(windows))] +extern crate tempfile; +#[cfg(unix)] +extern crate unix_socket; + +use self::regex::Regex; +use crate::common::util::*; + +/* + * As vdir use the same functions than ls, we don't have to retest them here. + * We just test the default and the column output +*/ + +#[test] +fn test_vdir() { + new_ucmd!().succeeds(); +} + +#[test] +fn test_default_output() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("some-dir1"); + at.touch("some-file1"); + + scene.ucmd().succeeds().stdout_contains("some-file1"); + + scene + .ucmd() + .succeeds() + .stdout_matches(&Regex::new("[rwx][^some-file1]").unwrap()); +} + +#[test] +fn test_column_output() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("some-dir1"); + at.touch("some-file1"); + + scene + .ucmd() + .arg("-C") + .succeeds() + .stdout_contains("some-file1"); + + scene + .ucmd() + .arg("-C") + .succeeds() + .stdout_does_not_match(&Regex::new("[rwx][^some-file1]").unwrap()); +} diff --git a/util/build-gnu.sh b/util/build-gnu.sh index a4a33e8604f..0aad35ff1d9 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -180,7 +180,7 @@ sed -i -e "s~ sed -n \"1s/'\\\/'/'OPT'/p\" < err >> pat || framework_failure_~ # see issue #3331 (clap limitation). # Upstream returns 1 for most of the program. We do for cp, truncate & pr # So, keep it as it -sed -i -e "s/rcexp=1$/rcexp=2\n case \"\$prg\" in chcon|dir|runcon|vdir) return;; esac/" -e "s/rcexp=125 ;;/rcexp=2 ;;\ncp|truncate|pr) rcexp=1;;/" tests/misc/usage_vs_getopt.sh +sed -i -e "s/rcexp=1$/rcexp=2\n case \"\$prg\" in chcon|runcon) return;; esac/" -e "s/rcexp=125 ;;/rcexp=2 ;;\ncp|truncate|pr) rcexp=1;;/" tests/misc/usage_vs_getopt.sh # GNU has option=[SUFFIX], clap is sed -i -e "s/cat opts/sed -i -e \"s| <.\*>$||g\" opts/" tests/misc/usage_vs_getopt.sh # Strip empty lines for the diff - see https://github.com/uutils/coreutils/issues/3370