shitbox/corebox/commands/nproc/mod.rs
Nathan Fisher 06b88d2c24 Refactoring:
- Split into workspace crates
- Split into two binaries `corebox` and `hashbox`
- Add `mount` crate to workspace to prepare for third binary `utilbox`
2023-02-05 23:50:59 -05:00

39 lines
1018 B
Rust

use super::Cmd;
use clap::{Arg, ArgAction, Command};
#[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: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
if matches.get_flag("ALL") {
println!("{}", unsafe { get_nprocs_conf() });
} else {
println!("{}", unsafe { get_nprocs() });
}
Ok(())
}
fn path(&self) -> Option<shitbox::Path> {
Some(shitbox::Path::UsrBin)
}
}
extern "C" {
fn get_nprocs() -> libc::c_int;
fn get_nprocs_conf() -> libc::c_int;
}