Nathan Fisher
06b88d2c24
- Split into workspace crates - Split into two binaries `corebox` and `hashbox` - Add `mount` crate to workspace to prepare for third binary `utilbox`
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
use super::Cmd;
|
|
use clap::{Arg, Command};
|
|
|
|
#[derive(Debug, Default)]
|
|
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"))
|
|
}
|
|
|
|
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
|
let groups = match matches.get_one::<String>("user") {
|
|
Some(u) => pw::get_group_names_for_name(u)?,
|
|
None => pw::get_group_names()?,
|
|
};
|
|
let len = groups.len();
|
|
for (idx, group) in groups.into_iter().enumerate() {
|
|
if idx < len - 1 {
|
|
print!("{group} ");
|
|
} else {
|
|
println!("{group}");
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn path(&self) -> Option<shitbox::Path> {
|
|
Some(shitbox::Path::UsrBin)
|
|
}
|
|
}
|