add --no-symlink option

This commit is contained in:
Abin Simon 2019-05-18 19:19:29 +05:30 committed by Pierre Peltier
parent 4767ef8c11
commit e145697b4e
3 changed files with 39 additions and 23 deletions

View file

@ -171,7 +171,7 @@ pub fn build() -> App<'static, 'static> {
.multiple(true) .multiple(true)
.number_of_values(1) .number_of_values(1)
.require_delimiter(true) .require_delimiter(true)
.possible_values(&["permission", "user", "group", "size", "date", "name","namewithoutsymlink" ]) .possible_values(&["permission", "user", "group", "size", "date", "name"])
.default_value("permission,user,group,size,date,name") .default_value("permission,user,group,size,date,name")
.help("Specify the blocks that will be displayed and in what order"), .help("Specify the blocks that will be displayed and in what order"),
) )
@ -180,4 +180,10 @@ pub fn build() -> App<'static, 'static> {
.long("classic") .long("classic")
.help("Enable classic mode (no colors or icons)"), .help("Enable classic mode (no colors or icons)"),
) )
.arg(
Arg::with_name("no-symlink")
.long("no-symlink")
.multiple(true)
.help("Do not display symlink target"),
)
} }

View file

@ -296,14 +296,20 @@ fn get_long_output(
&flags, &flags,
)), )),
Block::Date => strings.push(meta.date.render(colors, padding_rules.date, &flags)), Block::Date => strings.push(meta.date.render(colors, padding_rules.date, &flags)),
Block::Name => strings.push(meta.name.render(colors, icons, Some(padding_rules.name))), Block::Name => {
Block::NameWithSymlink => match meta.symlink.symlink_string() { if flags.no_symlink {
strings.push(meta.name.render(colors, icons, Some(padding_rules.name)));
} else {
match meta.symlink.symlink_string() {
Some(_) => { Some(_) => {
strings.push(meta.name.render(colors, icons, None)); strings.push(meta.name.render(colors, icons, None));
strings.push(meta.indicator.render(&flags)); strings.push(meta.indicator.render(&flags));
strings.push(meta.symlink.render( strings.push(meta.symlink.render(
colors, colors,
Some(padding_rules.name_with_symlink - meta.name.name_string(icons).len()), Some(
padding_rules.name_with_symlink
- meta.name.name_string(icons).len(),
),
)); ));
} }
None => { None => {
@ -315,7 +321,9 @@ fn get_long_output(
strings.push(meta.indicator.render(&flags)); strings.push(meta.indicator.render(&flags));
strings.push(meta.symlink.render(colors, None)); strings.push(meta.symlink.render(colors, None));
} }
}, }
}
}
}; };
strings.push(ANSIString::from(" ")); // TODO do not add this space to the end strings.push(ANSIString::from(" ")); // TODO do not add this space to the end
} }

View file

@ -16,6 +16,7 @@ pub struct Flags {
pub icon_theme: IconTheme, pub icon_theme: IconTheme,
pub recursion_depth: usize, pub recursion_depth: usize,
pub blocks: Vec<Block>, pub blocks: Vec<Block>,
pub no_symlink: bool,
} }
impl Flags { impl Flags {
@ -89,6 +90,7 @@ impl Flags {
} }
None => usize::max_value(), None => usize::max_value(),
}; };
let no_symlink = matches.is_present("no-symlink");
Ok(Self { Ok(Self {
display, display,
@ -122,6 +124,7 @@ impl Flags {
} else { } else {
DirOrderFlag::from(dir_order_inputs[dir_order_inputs.len() - 1]) DirOrderFlag::from(dir_order_inputs[dir_order_inputs.len() - 1])
}, },
no_symlink,
}) })
} }
} }
@ -150,6 +153,7 @@ impl Default for Flags {
Block::Date, Block::Date,
Block::Name, Block::Name,
], ],
no_symlink: false,
} }
} }
} }
@ -163,7 +167,6 @@ pub enum Block {
Size, Size,
Date, Date,
Name, Name,
NameWithSymlink,
} }
impl<'a> From<&'a str> for Block { impl<'a> From<&'a str> for Block {
fn from(block: &'a str) -> Self { fn from(block: &'a str) -> Self {
@ -174,8 +177,7 @@ impl<'a> From<&'a str> for Block {
"group" => Block::Group, "group" => Block::Group,
"size" => Block::Size, "size" => Block::Size,
"date" => Block::Date, "date" => Block::Date,
"name" => Block::NameWithSymlink, "name" => Block::Name,
"namewithoutsymlink" => Block::Name,
_ => panic!("invalid \"time\" flag: {}", block), _ => panic!("invalid \"time\" flag: {}", block),
} }
} }