coreutils/groups/groups.rs

61 lines
1.5 KiB
Rust
Raw Normal View History

2014-03-31 16:40:21 +00:00
#![crate_id(name="groups", vers="1.0.0", author="Alan Andrade")]
2014-02-25 17:23:58 +00:00
/*
* This file is part of the uutils coreutils package.
*
* (c) Alan Andrade <alan.andradec@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
2014-03-31 16:40:21 +00:00
#![feature(macro_rules)]
2014-02-25 17:23:58 +00:00
extern crate getopts;
use std::os;
use getopts::{
optflag,
getopts,
usage
};
use c_types::{get_pw_from_args, group};
#[path = "../common/util.rs"] mod util;
#[path = "../common/c_types.rs"] mod c_types;
static NAME: &'static str = "groups";
2014-06-15 07:17:20 +00:00
static VERSION: &'static str = "1.0.0";
2014-02-25 17:23:58 +00:00
#[allow(dead_code)]
fn main () { os::set_exit_status(uumain(os::args())); }
2014-05-28 11:43:37 +00:00
pub fn uumain(args: Vec<String>) -> int {
2014-06-15 07:17:20 +00:00
let program = args.get(0).clone();
2014-02-25 17:23:58 +00:00
let options = [
2014-06-15 07:17:20 +00:00
optflag("h", "help", "display this help menu and exit"),
optflag("V", "version", "display version information and exit")
];
2014-02-25 17:23:58 +00:00
let matches = match getopts(args.tail(), options) {
Ok(m) => { m },
2014-06-15 07:17:20 +00:00
Err(f) => {
2014-06-15 10:50:40 +00:00
show_error!("{}", f);
return 1;
2014-02-25 17:23:58 +00:00
}
};
2014-06-15 07:17:20 +00:00
if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else if matches.opt_present("help") {
print!("{} v{}\n\n\
Usage:\n \
{} [OPTION]... [USER]...\n\n\
{}", NAME, VERSION, program, usage("Prints the groups a user is in to standard output.", options));
} else {
group(get_pw_from_args(&matches.free), true);
}
0
2014-02-25 17:23:58 +00:00
}