Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add disable option for permission #882

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct Cli {
pub directory_only: bool,

/// How to display permissions [default: rwx]
#[arg(long, value_name = "MODE", value_parser = ["rwx", "octal"])]
#[arg(long, value_name = "MODE", value_parser = ["rwx", "octal", "disable"])]
pub permission: Option<String>,

/// How to display size [default: default]
Expand Down
4 changes: 2 additions & 2 deletions src/config_file.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module provides methods to handle the program's config files and
//! operations related to this.
use crate::flags::display::Display;
use crate::flags::icons::{IconOption, IconTheme};
use crate::flags::layout::Layout;
Expand All @@ -6,8 +8,6 @@ use crate::flags::size::SizeFlag;
use crate::flags::sorting::{DirGrouping, SortColumn};
use crate::flags::HyperlinkOption;
use crate::flags::{ColorOption, ThemeOption};
///! This module provides methods to handle the program's config files and operations related to
///! this.
use crate::print_error;

use std::path::{Path, PathBuf};
Expand Down
9 changes: 7 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::color::Colors;
use crate::display;
use crate::flags::{
ColorOption, Display, Flags, HyperlinkOption, Layout, Literal, SortOrder, ThemeOption,
ColorOption, Display, Flags, HyperlinkOption, Layout, Literal, PermissionFlag, SortOrder,
ThemeOption,
};
use crate::git::GitCache;
use crate::icon::Icons;
Expand Down Expand Up @@ -105,7 +106,11 @@ impl Core {
};

for path in paths {
let mut meta = match Meta::from_path(&path, self.flags.dereference.0) {
let mut meta = match Meta::from_path(
&path,
self.flags.dereference.0,
self.flags.permission == PermissionFlag::Disable,
) {
Ok(meta) => meta,
Err(err) => {
print_error!("{}: {}.", path.display(), err);
Expand Down
22 changes: 11 additions & 11 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ mod tests {
dir.child("one.d").create_dir_all().unwrap();
dir.child("one.d/two").touch().unwrap();
dir.child("one.d/.hidden").touch().unwrap();
let mut metas = Meta::from_path(Path::new(dir.path()), false)
let mut metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -716,7 +716,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("dir").create_dir_all().unwrap();
dir.child("dir/file").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -757,7 +757,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("dir").create_dir_all().unwrap();
dir.child("dir/file").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -797,7 +797,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("one.d").create_dir_all().unwrap();
dir.child("one.d/two").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -828,7 +828,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("testdir").create_dir_all().unwrap();
dir.child("test").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(1, &flags, None)
.unwrap()
Expand Down Expand Up @@ -862,7 +862,7 @@ mod tests {

let dir = assert_fs::TempDir::new().unwrap();
dir.child("testdir").create_dir_all().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(1, &flags, None)
.unwrap()
Expand Down Expand Up @@ -892,11 +892,11 @@ mod tests {

let file_path = tmp_dir.path().join("file");
std::fs::File::create(&file_path).expect("failed to create the file");
let file = Meta::from_path(&file_path, false).unwrap();
let file = Meta::from_path(&file_path, false, false).unwrap();

let dir_path = tmp_dir.path().join("dir");
std::fs::create_dir(&dir_path).expect("failed to create the dir");
let dir = Meta::from_path(&dir_path, false).unwrap();
let dir = Meta::from_path(&dir_path, false, false).unwrap();

assert_eq!(
display_folder_path(&dir),
Expand Down Expand Up @@ -942,15 +942,15 @@ mod tests {

let file_path = tmp_dir.path().join("file");
std::fs::File::create(&file_path).expect("failed to create the file");
let file = Meta::from_path(&file_path, false).unwrap();
let file = Meta::from_path(&file_path, false, false).unwrap();

let dir_path = tmp_dir.path().join("dir");
std::fs::create_dir(&dir_path).expect("failed to create the dir");
let dir = Meta::from_path(&dir_path, false).unwrap();
let dir = Meta::from_path(&dir_path, false, false).unwrap();

let link_path = tmp_dir.path().join("link");
std::os::unix::fs::symlink("dir", &link_path).unwrap();
let link = Meta::from_path(&link_path, false).unwrap();
let link = Meta::from_path(&link_path, false, false).unwrap();

let grid_flags = Flags {
layout: Layout::Grid,
Expand Down
2 changes: 1 addition & 1 deletion src/flags/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mod test_blocks {
fn test_from_cli_none() {
let argv = ["lsd"];
let cli = Cli::try_parse_from(argv).unwrap();
assert!(matches!(Blocks::from_cli(&cli), None));
assert!(Blocks::from_cli(&cli).is_none());
}

#[test]
Expand Down
7 changes: 2 additions & 5 deletions src/flags/ignore_globs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,11 @@ mod test {
fn test_from_cli_none() {
let argv = ["lsd"];
let cli = Cli::try_parse_from(argv).unwrap();
assert!(matches!(IgnoreGlobs::from_cli(&cli), None));
assert!(IgnoreGlobs::from_cli(&cli).is_none());
}

#[test]
fn test_from_config_none() {
assert!(matches!(
IgnoreGlobs::from_config(&Config::with_none()),
None
));
assert!(IgnoreGlobs::from_config(&Config::with_none()).is_none());
}
}
13 changes: 13 additions & 0 deletions src/flags/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ pub enum PermissionFlag {
Rwx,
/// The variant to show file permissions in octal format
Octal,
/// Disable the display of owner and permissions, may be used to speed up in Windows
Disable,
}

impl PermissionFlag {
fn from_arg_str(value: &str) -> Self {
match value {
"rwx" => Self::Rwx,
"octal" => Self::Octal,
"disable" => Self::Disable,
// Invalid value should be handled by `clap` when building an `Cli`
other => unreachable!("Invalid value '{other}' for 'permission'"),
}
Expand Down Expand Up @@ -96,6 +99,16 @@ mod test {
assert_eq!(Some(PermissionFlag::Octal), PermissionFlag::from_cli(&cli));
}

#[test]
fn test_from_cli_permissions_disable() {
let argv = ["lsd", "--permission", "disable"];
let cli = Cli::try_parse_from(argv).unwrap();
assert_eq!(
Some(PermissionFlag::Disable),
PermissionFlag::from_cli(&cli)
);
}

#[test]
#[should_panic]
fn test_from_cli_unknown() {
Expand Down
2 changes: 1 addition & 1 deletion src/flags/recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod test {
fn test_depth_from_cli_empty() {
let argv = ["lsd"];
let cli = Cli::try_parse_from(argv).unwrap();
assert!(matches!(cli.depth, None));
assert!(cli.depth.is_none());
}

#[test]
Expand Down
22 changes: 11 additions & 11 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(true, IconOption::Never, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -97,7 +97,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -110,7 +110,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(false, IconOption::Auto, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -122,7 +122,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(true, IconOption::Auto, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -135,7 +135,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(true, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -148,7 +148,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -161,7 +161,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(
false,
Expand All @@ -178,7 +178,7 @@ mod test {
fn get_icon_default_directory() {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path();
let meta = Meta::from_path(file_path, false).unwrap();
let meta = Meta::from_path(file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -190,7 +190,7 @@ mod test {
fn get_icon_default_directory_unicode() {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path();
let meta = Meta::from_path(file_path, false).unwrap();
let meta = Meta::from_path(file_path, false, false).unwrap();

let icon = Icons::new(
false,
Expand All @@ -210,7 +210,7 @@ mod test {
for (file_name, file_icon) in &IconTheme::get_default_icons_by_name() {
let file_path = tmp_dir.path().join(file_name);
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -226,7 +226,7 @@ mod test {
for (ext, file_icon) in &IconTheme::get_default_icons_by_extension() {
let file_path = tmp_dir.path().join(format!("file.{ext}"));
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand Down
2 changes: 1 addition & 1 deletion src/meta/filetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod test {
fn test_dir_type() {
let tmp_dir = tempdir().expect("failed to create temp dir");
#[cfg(not(windows))]
let meta = crate::meta::Meta::from_path(tmp_dir.path(), false)
let meta = crate::meta::Meta::from_path(tmp_dir.path(), false, false)
.expect("failed to get tempdir path");
let metadata = tmp_dir.path().metadata().expect("failed to get metas");

Expand Down
Loading
Loading