diff --git a/src/uu/lscpu/Cargo.toml b/src/uu/lscpu/Cargo.toml new file mode 100644 index 0000000..ad12f31 --- /dev/null +++ b/src/uu/lscpu/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "uu_lscpu" +version = "0.0.1" +edition = "2021" + +[[bin]] +name = "lscpu" +path = "src/lscpu.rs" + +[dependencies] +regex = { workspace = true } +sysinfo = { workspace = true } diff --git a/src/uu/lscpu/src/lscpu.rs b/src/uu/lscpu/src/lscpu.rs new file mode 100644 index 0000000..4f9432f --- /dev/null +++ b/src/uu/lscpu/src/lscpu.rs @@ -0,0 +1,31 @@ +use sysinfo::{System}; +use regex::Regex; +use std::fs; + +fn main() { + 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 + } + } +} + +fn get_architecture() -> String { + if cfg!(target_arch = "x86") { + "x86".to_string() + } else if cfg!(target_arch = "x86_64") { + "x86_64".to_string() + } else { + "Unknown".to_string() + } +}