match the coreutils style

This commit is contained in:
Sylvestre Ledru
2024-01-26 19:15:05 +01:00
parent 1b4b449d49
commit 4280abe67c
10 changed files with 149 additions and 1027 deletions

View File

@@ -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 }

View File

@@ -4,10 +4,16 @@
// 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();
@@ -15,7 +21,6 @@ fn main() {
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) {
@@ -23,6 +28,7 @@ fn main() {
break; // Assuming all CPUs have the same model name
}
}
Ok(())
}
fn get_architecture() -> String {
@@ -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)
}

View File

@@ -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"

View File

@@ -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 {
@@ -22,6 +29,7 @@ fn main() {
} else {
println!("{} is not a mountpoint", path);
}
Ok(())
}
fn is_mountpoint(path: &str) -> bool {
@@ -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)
}

View File

@@ -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"

View File

@@ -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 {
@@ -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)
}

View File

@@ -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"

View File

@@ -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 {
@@ -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)
}