2023-01-12 18:33:41 -05:00
|
|
|
use super::Cmd;
|
|
|
|
use clap::{Arg, Command};
|
|
|
|
|
2023-04-17 23:27:57 -04:00
|
|
|
#[derive(Debug)]
|
2023-01-12 18:33:41 -05:00
|
|
|
pub struct Groups;
|
|
|
|
|
|
|
|
impl Cmd for Groups {
|
|
|
|
fn cli(&self) -> clap::Command {
|
|
|
|
Command::new("groups")
|
|
|
|
.about("display current group names")
|
|
|
|
.author("Nathan Fisher")
|
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
|
|
|
.after_help(
|
|
|
|
"The groups command displays the current group names or ID values. \
|
|
|
|
If the value does not have a corresponding entry in /etc/group, the \
|
|
|
|
value will be displayed as the numerical group value. The optional \
|
|
|
|
user parameter will display the groups for the named user.",
|
|
|
|
)
|
|
|
|
.arg(Arg::new("user"))
|
|
|
|
}
|
|
|
|
|
2023-02-04 08:54:27 -05:00
|
|
|
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
2023-01-12 18:33:41 -05:00
|
|
|
let groups = match matches.get_one::<String>("user") {
|
2023-01-14 02:34:27 -05:00
|
|
|
Some(u) => pw::get_group_names_for_name(u)?,
|
2023-01-12 19:00:16 -05:00
|
|
|
None => pw::get_group_names()?,
|
2023-01-12 18:33:41 -05:00
|
|
|
};
|
|
|
|
let len = groups.len();
|
|
|
|
for (idx, group) in groups.into_iter().enumerate() {
|
|
|
|
if idx < len - 1 {
|
|
|
|
print!("{group} ");
|
|
|
|
} else {
|
|
|
|
println!("{group}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:50:59 -05:00
|
|
|
fn path(&self) -> Option<shitbox::Path> {
|
|
|
|
Some(shitbox::Path::UsrBin)
|
2023-01-12 18:33:41 -05:00
|
|
|
}
|
|
|
|
}
|