mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
groups: fix argument parsing
This commit is contained in:
parent
a9cf7baf68
commit
38c62a14d9
1 changed files with 18 additions and 5 deletions
|
@ -24,24 +24,37 @@ use c_types::{get_pw_from_args, group};
|
|||
#[path = "../common/c_types.rs"] mod c_types;
|
||||
|
||||
static NAME: &'static str = "groups";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn main () { os::set_exit_status(uumain(os::args())); }
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
let program = args.get(0).clone();
|
||||
|
||||
let options = [
|
||||
optflag("h", "", "Help")
|
||||
];
|
||||
optflag("h", "help", "display this help menu and exit"),
|
||||
optflag("V", "version", "display version information and exit")
|
||||
];
|
||||
|
||||
let matches = match getopts(args.tail(), options) {
|
||||
Ok(m) => { m },
|
||||
Err(_) => {
|
||||
show_error!("{}", usage(NAME, options));
|
||||
Err(f) => {
|
||||
show_error!("{}", f.to_err_msg());
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
group(get_pw_from_args(&matches.free), true);
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue