Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #3163: uutils: add dir and vdir utils #3405

Merged
merged 20 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/people.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,4 @@ Smigle00
anonymousknight
kwantam
nicoo
gmnsii
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/shell.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ rollup
sed
selinuxenabled
sestatus
vdir
wslpath
xargs

Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ feat_common_core = [
"cut",
"date",
"df",
"dir",
"dircolors",
"dirname",
"dd",
Expand Down Expand Up @@ -100,6 +101,7 @@ feat_common_core = [
"unexpand",
"uniq",
"unlink",
"vdir",
"wc",
"yes",
]
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ PROGS := \
date \
dd \
df \
dir \
dircolors \
dirname \
echo \
Expand Down Expand Up @@ -118,6 +119,7 @@ PROGS := \
tsort \
unexpand \
uniq \
vdir \
wc \
whoami \
yes
Expand Down
25 changes: 25 additions & 0 deletions src/uu/dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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:/uutils/coreutils"
repository = "https:/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"
1 change: 1 addition & 0 deletions src/uu/dir/LICENSE
70 changes: 70 additions & 0 deletions src/uu/dir/src/dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// * This file is part of the uutils coreutils package.
// *
// * (c) gmnsii <[email protected]>
// *
// * 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())
}
1 change: 1 addition & 0 deletions src/uu/dir/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uucore::bin!(uu_dir);
Loading