diff options
author | zwPapEr <zw.paper@gmail.com> | 2019-12-15 14:59:18 +0800 |
---|---|---|
committer | Abin Simon <abinsimon10@gmail.com> | 2020-01-11 14:17:44 +0530 |
commit | 11d10caf0fd4c9e8209fb41fac88121ac903d753 (patch) | |
tree | d33f9c7fb5f4d0d9f2fc12c35b41ebffca66b49d | |
parent | 1af45a10e8f3e4aae18955c33e5ea66c3db22e58 (diff) |
args: :sparkles: add inode(i) args for showing inode,name
-rw-r--r-- | src/app.rs | 8 | ||||
-rw-r--r-- | src/color.rs | 4 | ||||
-rw-r--r-- | src/flags.rs | 19 | ||||
-rw-r--r-- | src/meta/inode.rs | 4 |
4 files changed, 24 insertions, 11 deletions
@@ -210,6 +210,14 @@ pub fn build() -> App<'static, 'static> { .default_value("") .help("Do not display files/directories with names matching the glob pattern(s)"), ) + .arg( + Arg::with_name("inode") + .short("i") + .long("inode") + .multiple(true) + .conflicts_with("blocks") + .help("Display inode and file names"), + ) } fn validate_date_argument(arg: String) -> Result<(), String> { diff --git a/src/color.rs b/src/color.rs index 5823a67..943a1d0 100644 --- a/src/color.rs +++ b/src/color.rs @@ -46,7 +46,7 @@ pub enum Elem { /// INode INode { valid: bool, - } + }, } impl Elem { @@ -156,7 +156,7 @@ impl Colors { } else { Some("di") } - }, + } Elem::SymLink => Some("ln"), Elem::Pipe => Some("pi"), Elem::Socket => Some("so"), diff --git a/src/flags.rs b/src/flags.rs index 6c6de7f..003ee57 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -15,6 +15,7 @@ pub struct Flags { pub color: WhenFlag, pub icon: WhenFlag, pub icon_theme: IconTheme, + pub inode: bool, pub recursion_depth: usize, pub blocks: Vec<Block>, pub no_symlink: bool, @@ -32,6 +33,8 @@ impl Flags { let date_inputs: Vec<&str> = matches.values_of("date").unwrap().collect(); let dir_order_inputs: Vec<&str> = matches.values_of("group-dirs").unwrap().collect(); let ignore_globs_inputs: Vec<&str> = matches.values_of("ignore-glob").unwrap().collect(); + // inode set layout to oneline and blocks to inode,name + let inode = matches.is_present("inode"); let blocks_inputs: Vec<&str> = if let Some(blocks) = matches.values_of("blocks") { blocks.collect() } else { @@ -67,6 +70,7 @@ impl Flags { } else if matches.is_present("long") || matches.is_present("oneline") || blocks_inputs.len() > 1 + || inode { Layout::OneLine } else { @@ -94,19 +98,18 @@ impl Flags { None => usize::max_value(), }; - let blocks: Vec<Block> = if !blocks_inputs.is_empty() { - blocks_inputs.into_iter().map(Block::from).collect() - } else if matches.is_present("long") { - vec![ + let blocks: Vec<Block> = match () { + _ if inode => vec![Block::INode, Block::Name], + _ if !blocks_inputs.is_empty() => blocks_inputs.into_iter().map(Block::from).collect(), + _ if matches.is_present("long") => vec![ Block::Permission, Block::User, Block::Group, Block::Size, Block::Date, Block::Name, - ] - } else { - vec![Block::Name] + ], + _ => vec![Block::Name], }; let mut ignore_globs_builder = GlobSetBuilder::new(); @@ -168,6 +171,7 @@ impl Flags { }, no_symlink: matches.is_present("no-symlink"), total_size: matches.is_present("total-size"), + inode, }) } } @@ -192,6 +196,7 @@ impl Default for Flags { no_symlink: false, total_size: false, ignore_globs: GlobSet::empty(), + inode: false, } } } diff --git a/src/meta/inode.rs b/src/meta/inode.rs index 9bc67d9..6849947 100644 --- a/src/meta/inode.rs +++ b/src/meta/inode.rs @@ -25,8 +25,8 @@ impl<'a> From<&'a Metadata> for INode { impl INode { pub fn render(&self, colors: &Colors) -> ColoredString { match self.index { - Some(i) => colors.colorize(i.to_string(), &Elem::INode{ valid: true }), - None => colors.colorize(String::from("-"), &Elem::INode{ valid: false }), + Some(i) => colors.colorize(i.to_string(), &Elem::INode { valid: true }), + None => colors.colorize(String::from("-"), &Elem::INode { valid: false }), } } } |