From 7ca7290e238ae534fb1e04aed165f9a77b8eb1ba Mon Sep 17 00:00:00 2001 From: zwPapEr Date: Sun, 22 Dec 2019 20:20:52 +0800 Subject: [PATCH] args/inode: :hammer: inode work with long --- src/app.rs | 3 +-- src/flags.rs | 8 ++++++-- tests/integration.rs | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index d60568b..4e282d6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -215,8 +215,7 @@ pub fn build() -> App<'static, 'static> { .short("i") .long("inode") .multiple(true) - .conflicts_with("blocks") - .help("Display inode and file names"), + .help("Display inode(Linux only)"), ) } diff --git a/src/flags.rs b/src/flags.rs index 003ee57..8564dbe 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -98,8 +98,7 @@ impl Flags { None => usize::max_value(), }; - let blocks: Vec = match () { - _ if inode => vec![Block::INode, Block::Name], + let mut blocks: Vec = match () { _ if !blocks_inputs.is_empty() => blocks_inputs.into_iter().map(Block::from).collect(), _ if matches.is_present("long") => vec![ Block::Permission, @@ -112,6 +111,11 @@ impl Flags { _ => vec![Block::Name], }; + // Add inode as first column if with inode flag + if inode && !blocks.contains(&Block::INode) { + blocks.insert(0, Block::INode); + } + let mut ignore_globs_builder = GlobSetBuilder::new(); for pattern in ignore_globs_inputs { let glob = match Glob::new(pattern) { diff --git a/tests/integration.rs b/tests/integration.rs index f662040..05dfa95 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -128,6 +128,12 @@ fn test_list_block_inode_populated_directory() { .stdout(predicate::str::is_match(matched).unwrap()); } +#[test] +fn test_list_inode_with_long_ok() { + let dir = tempdir(); + cmd().arg("-i").arg("-l").arg(dir.path()).assert().success(); +} + fn cmd() -> Command { Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap() }