mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
commit
d0890b72cd
3 changed files with 48 additions and 26 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1334,6 +1334,7 @@ dependencies = [
|
||||||
name = "uu_groups"
|
name = "uu_groups"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"uucore 0.0.4 (git+https://github.com/uutils/uucore.git?branch=canary)",
|
"uucore 0.0.4 (git+https://github.com/uutils/uucore.git?branch=canary)",
|
||||||
"uucore_procs 0.0.4 (git+https://github.com/uutils/uucore.git?branch=canary)",
|
"uucore_procs 0.0.4 (git+https://github.com/uutils/uucore.git?branch=canary)",
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,6 +17,7 @@ path = "src/groups.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uucore = { version="0.0.4", package="uucore", git="https://github.com/uutils/uucore.git", branch="canary", features=["entries"] }
|
uucore = { version="0.0.4", package="uucore", git="https://github.com/uutils/uucore.git", branch="canary", features=["entries"] }
|
||||||
uucore_procs = { version="0.0.4", package="uucore_procs", git="https://github.com/uutils/uucore.git", branch="canary" }
|
uucore_procs = { version="0.0.4", package="uucore_procs", git="https://github.com/uutils/uucore.git", branch="canary" }
|
||||||
|
clap = "2.32"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "groups"
|
name = "groups"
|
||||||
|
|
|
@ -12,34 +12,54 @@
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
use uucore::entries::{get_groups, gid2grp, Locate, Passwd};
|
use uucore::entries::{get_groups, gid2grp, Locate, Passwd};
|
||||||
|
|
||||||
static SYNTAX: &str = "[user]";
|
extern crate clap;
|
||||||
static SUMMARY: &str = "display current group names";
|
use clap::{App, Arg};
|
||||||
|
|
||||||
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
static ABOUT: &str = "display current group names";
|
||||||
|
static OPT_USER: &str = "user";
|
||||||
|
|
||||||
|
fn get_usage() -> String {
|
||||||
|
format!("{0} [USERNAME]", executable!())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let matches = app!(SYNTAX, SUMMARY, "").parse(args);
|
let usage = get_usage();
|
||||||
|
|
||||||
if matches.free.is_empty() {
|
let matches = App::new(executable!())
|
||||||
println!(
|
.version(VERSION)
|
||||||
"{}",
|
.about(ABOUT)
|
||||||
get_groups()
|
.usage(&usage[..])
|
||||||
.unwrap()
|
.arg(Arg::with_name(OPT_USER))
|
||||||
.iter()
|
.get_matches_from(&args);
|
||||||
.map(|&g| gid2grp(g).unwrap())
|
|
||||||
.collect::<Vec<_>>()
|
match matches.value_of(OPT_USER) {
|
||||||
.join(" ")
|
None => {
|
||||||
);
|
println!(
|
||||||
} else if let Ok(p) = Passwd::locate(matches.free[0].as_str()) {
|
"{}",
|
||||||
println!(
|
get_groups()
|
||||||
"{}",
|
.unwrap()
|
||||||
p.belongs_to()
|
.iter()
|
||||||
.iter()
|
.map(|&g| gid2grp(g).unwrap())
|
||||||
.map(|&g| gid2grp(g).unwrap())
|
.collect::<Vec<_>>()
|
||||||
.collect::<Vec<_>>()
|
.join(" ")
|
||||||
.join(" ")
|
);
|
||||||
);
|
0
|
||||||
} else {
|
}
|
||||||
crash!(1, "unknown user {}", matches.free[0]);
|
Some(user) => {
|
||||||
|
if let Ok(p) = Passwd::locate(user) {
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
p.belongs_to()
|
||||||
|
.iter()
|
||||||
|
.map(|&g| gid2grp(g).unwrap())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
);
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
crash!(1, "unknown user {}", user);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue