Skip to content

Commit

Permalink
match the coreutils style
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 26, 2024
1 parent 1b4b449 commit 4280abe
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 1,027 deletions.
925 changes: 43 additions & 882 deletions Cargo.lock

Large diffs are not rendered by default.

147 changes: 13 additions & 134 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,164 +23,43 @@ build = "build.rs"

[features]
default = ["feat_common_core"]
## OS feature shortcodes

nightly = []
test_unimplemented = []
# * only build `uudoc` when `--feature uudoc` is activated
## features
# "feat_acl" == enable support for ACLs (access control lists; by using`--features feat_acl`)
# NOTE:
# * On linux, the posix-acl/acl-sys crate requires `libacl` headers and shared library to be accessible in the C toolchain at compile time.
# * On FreeBSD and macOS this is not required.

##
## feature sets
## (common/core and Tier1) feature sets
# "feat_common_core" == baseline core set of utilities which can be built/run on most targets

feat_common_core = [
"uu_pwdx",
"uu_renice",
"uu_lscpu",
"pwdx",
"renice",
"mountpoint",
"lscpu",
]

[workspace.dependencies]
bigdecimal = "0.4"
binary-heap-plus = "0.5.0"
bstr = "1.9"
bytecount = "0.6.7"
byteorder = "1.5.0"
chrono = { version = "^0.4.31", default-features = false, features = [
"std",
"alloc",
"clock",
] }
uucore = "0.0.24"
clap = { version = "4.4", features = ["wrap_help", "cargo"] }
clap_complete = "4.4"
clap_mangen = "0.2"
compare = "0.1.0"
coz = { version = "0.1.3" }
crossterm = ">=0.27.0"
ctrlc = { version = "3.4", features = ["termination"] }
exacl = "0.11.0"
file_diff = "1.0.0"
filetime = "0.2"
fnv = "1.0.7"
fs_extra = "1.3.0"
fts-sys = "0.2"
fundu = "2.0.0"
gcd = "2.3"
glob = "0.3.1"
half = "2.3"
hostname = "0.3"
indicatif = "0.17"
itertools = "0.12.0"
regex = "1.10.2"
sysinfo = "0.30"
libc = "0.2.152"
lscolors = { version = "0.16.0", default-features = false, features = [
"gnu_legacy",
] }
memchr = "2"
memmap2 = "0.9"
nix = { version = "0.27", default-features = false }
nom = "7.1.3"
notify = { version = "=6.0.1", features = ["macos_kqueue"] }
num-bigint = "0.4.4"
num-traits = "0.2.17"
number_prefix = "0.4"
once_cell = "1.19.0"
onig = { version = "~6.4", default-features = false }
parse_datetime = "0.5.0"
phf = "0.11.2"
phf_codegen = "0.11.2"
platform-info = "2.0.2"
quick-error = "2.0.1"
rand = { version = "0.8", features = ["small_rng"] }
rand_core = "0.6"
rayon = "1.8"
redox_syscall = "0.4"
regex = "1.10.2"
rstest = "0.18.2"
rust-ini = "0.19.0"
same-file = "1.0.6"
self_cell = "1.0.3"
selinux = "0.4"
signal-hook = "0.3.17"
smallvec = { version = "1.11", features = ["union"] }
tempfile = "3.9.0"
uutils_term_grid = "0.3"
terminal_size = "0.3.0"
textwrap = { version = "0.16.0", features = ["terminal_size"] }
thiserror = "1.0"
time = { version = "0.3" }
unicode-segmentation = "1.10.1"
unicode-width = "0.1.11"
utf-8 = "0.7.6"
walkdir = "2.4"
winapi-util = "0.1.6"
windows-sys = { version = "0.48.0", default-features = false }
xattr = "1.2.0"
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }
sysinfo = "0.30"

hex = "0.4.3"
md-5 = "0.10.6"
sha1 = "0.10.6"
sha2 = "0.10.8"
sha3 = "0.10.8"
blake2b_simd = "1.0.2"
blake3 = "1.5.0"
sm3 = "0.4.2"
digest = "0.10.7"


[dependencies]
clap = { workspace = true }
once_cell = { workspace = true }
clap_complete = { workspace = true }
clap_mangen = { workspace = true }
uucore = { workspace = true }
phf = { workspace = true }
selinux = { workspace = true, optional = true }
textwrap = { workspace = true }
zip = { workspace = true, optional = true }

#
uu_pwdx = { optional = true, version = "0.0.1", package = "uu_pwdx", path = "src/uu/pwdx" }
uu_lscpu = { optional = true, version = "0.0.1", package = "uu_lscpu", path = "src/uu/lscpu" }
uu_renice = { optional = true, version = "0.0.1", package = "uu_renice", path = "src/uu/renice" }
uu_mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", path = "src/uu/mountpoint" }

# this breaks clippy linting with: "tests/by-util/test_factor_benches.rs: No such file or directory (os error 2)"
# factor_benches = { optional = true, version = "0.0.0", package = "uu_factor_benches", path = "tests/benches/factor" }

#
# * pinned transitive dependencies
# Not needed for now. Keep as examples:
#pin_cc = { version="1.0.61, < 1.0.62", package="cc" } ## cc v1.0.62 has compiler errors for MinRustV v1.32.0, requires 1.34 (for `std::str::split_ascii_whitespace()`)
pwdx = { optional = true, version = "0.0.1", package = "uu_pwdx", path = "src/uu/pwdx" }
lscpu = { optional = true, version = "0.0.1", package = "uu_lscpu", path = "src/uu/lscpu" }
renice = { optional = true, version = "0.0.1", package = "uu_renice", path = "src/uu/renice" }
mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", path = "src/uu/mountpoint" }

[dev-dependencies]
chrono = { workspace = true }
conv = "0.3"
filetime = { workspace = true }
glob = { workspace = true }
libc = { workspace = true }
pretty_assertions = "1"
rand = { workspace = true }
regex = { workspace = true }
sha1 = { version = "0.10", features = ["std"] }
tempfile = { workspace = true }
time = { workspace = true, features = ["local-offset"] }
unindent = "0.2"
walkdir = { workspace = true }
hex-literal = "0.4.1"
rstest = { workspace = true }

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
procfs = { version = "0.16", default-features = false }
rlimit = "0.10.1"

[target.'cfg(unix)'.dev-dependencies]
nix = { workspace = true, features = ["process", "signal", "user"] }
rand_pcg = "0.3"

[build-dependencies]
phf_codegen = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions src/uu/lscpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ name = "uu_lscpu"
version = "0.0.1"
edition = "2021"

[[bin]]
name = "lscpu"
[lib]
path = "src/lscpu.rs"

[[bin]]
name = "mountpoint"
path = "src/main.rs"

[dependencies]
regex = { workspace = true }
sysinfo = { workspace = true }
uucore = { workspace = true }
clap = { workspace = true }
21 changes: 18 additions & 3 deletions src/uu/lscpu/src/lscpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
// file that was distributed with this source code.

use regex::Regex;
use std::fs;
use uucore::{error::UResult, format_usage, help_about, help_usage};
use clap::{crate_version, Command};
use std::{fs};
use sysinfo::System;

fn main() {
const ABOUT: &str = help_about!("lscpu.md");
const USAGE: &str = help_usage!("lscpu.md");

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let system = System::new_all();
let cpu = system.global_cpu_info();

println!("Architecture: {}", get_architecture());
println!("CPU(s): {}", system.cpus().len());
// Add more CPU information here...

// Example: Parsing /proc/cpuinfo for additional details
if let Ok(contents) = fs::read_to_string("/proc/cpuinfo") {
let re = Regex::new(r"^model name\s+:\s+(.*)$").unwrap();
for cap in re.captures_iter(&contents) {
println!("Model name: {}", &cap[1]);
break; // Assuming all CPUs have the same model name
}
}
Ok(())
}

fn get_architecture() -> String {
Expand All @@ -34,3 +40,12 @@ fn get_architecture() -> String {
"Unknown".to_string()
}
}


pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
}
7 changes: 6 additions & 1 deletion src/uu/mountpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
uucore = { workspace = true }
clap = { workspace = true }

[lib]
path = "src/mountpoint.rs"

[[bin]]
name = "mountpoint"
path = "src/mountpoint.rs"
path = "src/main.rs"
19 changes: 18 additions & 1 deletion src/uu/mountpoint/src/mountpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ use std::env;
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::process;
use uucore::{error::UResult, format_usage, help_about, help_usage};
use clap::{crate_version, Command};

const ABOUT: &str = help_about!("mountpoint.md");
const USAGE: &str = help_usage!("mountpoint.md");

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {

fn main() {
let args: Vec<String> = env::args().collect();

if args.len() != 2 {
Expand All @@ -22,6 +29,7 @@ fn main() {
} else {
println!("{} is not a mountpoint", path);
}
Ok(())
}

fn is_mountpoint(path: &str) -> bool {
Expand All @@ -40,3 +48,12 @@ fn is_mountpoint(path: &str) -> bool {
Err(_) => false,
}
}


pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
}
7 changes: 6 additions & 1 deletion src/uu/pwdx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
uucore = { workspace = true }
clap = { workspace = true }

[lib]
path = "src/pwdx.rs"

[[bin]]
name = "pwdx"
path = "src/pwdx.rs"
path = "src/main.rs"
18 changes: 17 additions & 1 deletion src/uu/pwdx/src/pwdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ use std::env;
use std::fs;
use std::path::Path;
use std::process;
use clap::{crate_version, Command};

fn main() {
use uucore::{error::UResult, format_usage, help_about, help_usage};

const ABOUT: &str = help_about!("pwdx.md");
const USAGE: &str = help_usage!("pwdx.md");

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args: Vec<String> = env::args().collect();

if args.len() != 2 {
Expand All @@ -26,4 +33,13 @@ fn main() {
process::exit(1);
}
}
Ok(())
}

pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
}
7 changes: 6 additions & 1 deletion src/uu/renice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ edition = "2021"

[dependencies]
libc = { workspace = true }
uucore = { workspace = true }
clap = { workspace = true }

[lib]
path = "src/renice.rs"

[[bin]]
name = "renice"
path = "src/renice.rs"
path = "src/main.rs"
16 changes: 15 additions & 1 deletion src/uu/renice/src/renice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ use std::env;
use std::io::Error;
use std::process;
use std::str::FromStr;
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("renice.md");
const USAGE: &str = help_usage!("renice.md");
use clap::{crate_version, Command};

fn main() {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args: Vec<String> = env::args().collect();

if args.len() != 3 {
Expand All @@ -33,4 +38,13 @@ fn main() {
}

println!("Nice value of process {} set to {}", pid, nice_value);
Ok(())
}

pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
}

0 comments on commit 4280abe

Please sign in to comment.