Skip to content

Commit

Permalink
feat: Add option --numeric-uid-gid to ls
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Jan 26, 2024
1 parent 8c5bbb2 commit 3238ac7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/commands/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub(crate) struct LsCmd {
#[clap(long, short = 'l')]
long: bool,

/// show uid/gid instead of user/group
#[clap(long)]
numeric_uid_gid: bool,

/// Listing options
#[clap(flatten)]
ls_opts: LsOptions,
Expand Down Expand Up @@ -103,7 +107,7 @@ impl LsCmd {
let (path, node) = item?;
summary.update(&node);
if self.long {
print_node(&node, &path);
print_node(&node, &path, self.numeric_uid_gid);
} else {
println!("{path:?} ");
}
Expand All @@ -126,7 +130,7 @@ impl LsCmd {
///
/// * `node` - the node to print
/// * `path` - the path of the node
fn print_node(node: &Node, path: &Path) {
fn print_node(node: &Node, path: &Path, numeric_uid_gid: bool) {
println!(
"{:>1}{:>9} {:>8} {:>8} {:>9} {:>12} {path:?} {}",
match node.node_type {
Expand All @@ -142,8 +146,18 @@ fn print_node(node: &Node, path: &Path) {
.mode
.map(parse_permissions)
.unwrap_or_else(|| "?????????".to_string()),
node.meta.user.clone().unwrap_or_else(|| "?".to_string()),
node.meta.group.clone().unwrap_or_else(|| "?".to_string()),
if numeric_uid_gid {
node.meta.uid.map(|uid| uid.to_string())
} else {
node.meta.user.clone()
}
.unwrap_or_else(|| "?".to_string()),
if numeric_uid_gid {
node.meta.gid.map(|uid| uid.to_string())
} else {
node.meta.group.clone()
}
.unwrap_or_else(|| "?".to_string()),
node.meta.size,
node.meta
.mtime
Expand Down

0 comments on commit 3238ac7

Please sign in to comment.