use super::Cmd; use clap::{Arg, ArgAction, Command}; use std::io; #[derive(Debug, Default)] pub struct Nproc; impl Cmd for Nproc { fn cli(&self) -> clap::Command { Command::new("nproc") .author("Nathan Fisher") .about("Print the number of processing units available") .arg( Arg::new("ALL") .help("Print the number of installed processors") .short('a') .long("all") .action(ArgAction::SetTrue), ) } fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box> { let Some(matches) = matches else { return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input"))); }; if matches.get_flag("ALL") { println!("{}", num_cpus::get()); } else { println!("{}", num_cpus::get_physical()); } Ok(()) } fn path(&self) -> Option { Some(crate::Path::UsrBin) } }