1
0
mirror of https://github.com/uutils/coreutils synced 2024-07-09 04:06:02 +00:00

add nproc

This commit is contained in:
Michael Gehring 2014-10-18 23:17:33 +02:00
parent 1f37abcc9c
commit 09af3ecaa2
3 changed files with 52 additions and 1 deletions

View File

@ -56,6 +56,7 @@ PROGS := \
mkdir \
mv \
nl \
nproc \
paste \
printenv \
pwd \

View File

@ -144,7 +144,6 @@ To do
- mktemp
- mv
- nice
- nproc
- numfmt
- od
- pathchk

51
src/nproc/nproc.rs Normal file
View File

@ -0,0 +1,51 @@
#![crate_name = "nproc"]
/*
* This file is part of the uutils coreutils package.
*
* (c) Michael Gehring <mg@ebfe.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
extern crate getopts;
use std::os;
static NAME : &'static str = "nproc";
static VERSION : &'static str = "0.0.0";
pub fn uumain(args: Vec<String>) -> int {
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
Ok(m) => m,
Err(err) => fail!("{}", err),
};
if matches.opt_present("version") {
println!("{} {}", NAME, VERSION);
return 0;
}
if matches.opt_present("help") {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");
println!(" {} [OPTIONS] NAME...", NAME);
println!("");
print!("{}", getopts::usage("Print the number of cores available.", opts.as_slice()).as_slice());
if matches.free.is_empty() {
return 1;
}
return 0;
}
println!("{}", os::num_cpus());
return 0
}