diff options
author | Canop <cano.petrole@gmail.com> | 2022-03-04 21:38:57 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-03-04 21:38:57 +0100 |
commit | d7dec233de26e379a334f9fbfe213ee0cfcffca0 (patch) | |
tree | d1be4673687b264220f4d817ff7587c0e7fc22d8 | |
parent | e51128ac7a1391578ff05270741faf609c21884e (diff) |
version 2.4.0v2.4.0
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | Cargo.lock | 6 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | src/args.rs | 4 | ||||
-rw-r--r-- | src/col_expr.rs | 16 | ||||
-rw-r--r-- | src/json.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 21 | ||||
-rw-r--r-- | website/docs/filters.md | 70 | ||||
-rw-r--r-- | website/docs/img/filters.png | bin | 0 -> 51026 bytes | |||
-rw-r--r-- | website/docs/index.md | 5 | ||||
-rw-r--r-- | website/docs/table.md | 32 | ||||
-rw-r--r-- | website/mkdocs.yml | 1 |
13 files changed, 118 insertions, 50 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb3f7c..3f901b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ -### next +<a name="v2.4.0"></a> +### v2.4.0 - 2022/03/04 - 'unreachable' information available in JSON and in the table (in the 'use' column). This mostly concerns disconnected remote filesystems. - `--filter` argument to filter the displayed filesystems - Fix #41 @@ -249,7 +249,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lfs" -version = "2.4.0-dev" +version = "2.4.0" dependencies = [ "argh", "bet", @@ -263,9 +263,9 @@ dependencies = [ [[package]] name = "lfs-core" -version = "0.10.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3e0aa8084f3ffcf29e701228fd720a7aee41111bc90b6bac38ed9b5cc33e3c" +checksum = "f350c0a93811c29222fb92129c9d98182859208ceeaa3964023c95e22b71889e" dependencies = [ "lazy-regex", "libc", @@ -1,6 +1,6 @@ [package] name = "lfs" -version = "2.4.0-dev" +version = "2.4.0" authors = ["dystroy <denys.seguret@gmail.com>"] edition = "2021" keywords = ["linux", "filesystem", "fs"] @@ -16,7 +16,7 @@ argh = "0.1.7" bet = "1.0.0" crossterm = "0.22.1" file-size = "1.0.3" -lfs-core = "0.10.2" +lfs-core = "0.11.0" serde = "1.0" serde_json = "1.0" termimad = "0.20.0" @@ -35,4 +35,8 @@ Complete documentation lives at **[https://dystroy.org/lfs](https://dystroy.org/ ![screenshot](website/docs/img/json-jq-tour.png) +### Filters + +![screenshot](website/docs/img/filters.png) + diff --git a/src/args.rs b/src/args.rs index ef2fecd..d0b10ba 100644 --- a/src/args.rs +++ b/src/args.rs @@ -31,6 +31,10 @@ pub struct Args { #[argh(switch)] pub list_cols: bool, + /// fetch stats of remote volumes, 'yes', 'no' or 'auto' + #[argh(option, default = "Default::default()")] + pub remote_stats: BoolArg, + /// columns, eg `-c +inodes` or `-c id+dev+default` #[argh(option, default = "Default::default()", short = 'c')] pub cols: Cols, diff --git a/src/col_expr.rs b/src/col_expr.rs index 9ff5402..d2b7082 100644 --- a/src/col_expr.rs +++ b/src/col_expr.rs @@ -95,7 +95,7 @@ impl ColExpr { ), Col::Remote => self.operator.eval( mount.info.is_remote(), - parse_bool(&self.value), + parse_bool(&self.value)?, ), Col::Disk => self.operator.eval_option_str( mount.disk.as_ref().map(|d| d.name.as_str()), @@ -233,6 +233,7 @@ pub enum EvalExprError { NotANumber(String), NotAnId(String), NotADeviceId(String), + NotABool(String), } impl EvalExprError { } @@ -248,14 +249,21 @@ impl fmt::Display for EvalExprError { Self::NotADeviceId(s) => { write!(f, "{:?} can't be evaluated as a device id", &s) } + Self::NotABool(s) => { + write!(f, "{:?} can't be evaluated as a boolean", &s) + } } } } impl std::error::Error for EvalExprError {} -fn parse_bool(s: &str) -> bool { - let s = s.to_lowercase(); - s == "x" || s == "true" || s == "yes" || s == "1" +fn parse_bool(input: &str) -> Result<bool, EvalExprError> { + let s = input.to_lowercase(); + match s.as_ref() { + "x" | "t" | "true" | "1" | "y" | "yes" => Ok(true), + "f" | "false" | "0" | "n" | "no" => Ok(false), + _ => Err(EvalExprError::NotABool(input.to_string())), + } } /// Parse numbers like "1234", "32G", "4kB", "54Gib", "1.2M" diff --git a/src/json.rs b/src/json.rs index 6fe2088..1c47281 100644 --- a/src/json.rs +++ b/src/json.rs @@ -4,7 +4,7 @@ use { serde_json::{json, Value}, }; -pub fn output_value(mounts: &[Mount], units: Units) -> Value { +pub fn output_value(mounts: &[&Mount], units: Units) -> Value { Value::Array( mounts .iter() diff --git a/src/main.rs b/src/main.rs index ede0a5b..2a92000 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,12 @@ fn main() { list_cols::print(args.color()); return; } - let mut mounts = match lfs_core::read_mounts() { + let mut options = lfs_core::ReadOptions::default(); + options.remote_stats(match args.remote_stats.value() { + Some(false) => false, + _ => true, + }); + let mut mounts = match lfs_core::read_mounts(&options) { Ok(mounts) => mounts, Err(e) => { eprintln!("Error reading mounts: {}", e); @@ -53,13 +58,6 @@ fn main() { let dev = lfs_core::DeviceId::from(md.dev()); mounts.retain(|m| m.info.dev == dev); } - if args.json { - println!( - "{}", - serde_json::to_string_pretty(&json::output_value(&mounts, args.units)).unwrap() - ); - return; - } args.sort.sort(&mut mounts); let mounts = match args.filter.filter(&mounts) { Ok(mounts) => mounts, @@ -68,6 +66,13 @@ fn main() { return; } }; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&json::output_value(&mounts, args.units)).unwrap() + ); + return; + } if mounts.is_empty() { println!("no mount to display - try\n lfs -a"); return; diff --git a/website/docs/filters.md b/website/docs/filters.md new file mode 100644 index 0000000..17f6660 --- /dev/null +++ b/website/docs/filters.md @@ -0,0 +1,70 @@ + +There are several ways to choose the filesystems of either the table or the JSON output: + +* [Choose between the "normal" ones or all of them](#normality) +* [Select the filesystem containing a specific path](#current-filesystem) +* [Use the rich query syntax of the `--filter` argument](#filter-argument) + +# Normality + +The default selection of filesystems showcases your storage, avoiding any filesystem which both have no "disk" and aren't remote ones, bound to another filesystem, etc. + +![screen](img/rows-standard.png) + +Here are the rules of the current heuristics, in order: a filesystem + +1. is excluded when it's bound to a previous one +1. is excluded when it's of type `squashfs` +1. is included when it's of type `zfs` +1. is included when it's remote +1. is excluded when no underlying disk was found + +To see *all* filesystems of your system, do `lfs --all`: + +![screen](img/rows-all.png) + +This list can be quite big with virtual file systems, docker use, etc. + +# Current filesystem + +If you're only interested in the device on which some file is, give the path as argument. + +For example, for the current device, use `lfs .`: + +![screen](img/rows-current.png) + +# Filter argument + +The `--filter` argument, shortened in `-f`, lets you specify a constraint, or combine several ones. + +A constraint can be related to any [column](../table#all-columns). + +You can for example fetch the filesystems with a given type with `lfs -f 'type=xfs'`. + +The operators you can apply to a column are the following ones: + +|operator|meaning| +|-|-| +|<| lower +|<=| lower or equal +|>| greater +|>=| greater or equal +|<>| different +|=| somehow equal - for example `fs=sda` matches `/dev/sda1` +|==|really equal + +You can combine several column conditions with boolean operators `|` (or), `&` (and) and `!` (not) and if needed you can use parenthesis. + +For example you may want to select the volumes with not enough space with + +```bash +lfs -f 'free<100G | use>75%' +``` + +Examples: + +![screen](img/filters.png) + +!!! Note + Only *normal* filesystems are shown unless you use `-a`. This applies even when you use the `--filter` argument. + diff --git a/website/docs/img/filters.png b/website/docs/img/filters.png Binary files differnew file mode 100644 index 0000000..761f4e1 --- /dev/null +++ b/website/docs/img/filters.png diff --git a/website/docs/index.md b/website/docs/index.md index ea42e26..31ac611 100644 --- a/website/docs/index.md +++ b/website/docs/index.md @@ -34,3 +34,8 @@ See [Table](./table) for the definition of the columns and the syntax for choosi ![screen](img/json-jq-tour.png) +# Filters + +The query syntax lets you specify the filesystems you want: + +![screen](img/filters.png) diff --git a/website/docs/table.md b/website/docs/table.md index 8b49aaf..ad8aaab 100644 --- a/website/docs/table.md +++ b/website/docs/table.md @@ -72,37 +72,7 @@ Here's removing the `fs` column and moving the `type` column to the end, with `l ![screen](img/c=-fs+type.png) -# Rows - -## Normality - -The default selection of filesystems showcases your storage, avoiding any filesystem which both have no "disk" and aren't remote ones, bound to another filesystem, etc. - -![screen](img/rows-standard.png) - -Here are the rules of the current heuristics, in order: a filesystem - -1. is excluded when it's bound to a previous one -1. is excluded when it's of type `squashfs` -1. is included when it's of type `zfs` -1. is included when it's remote -1. is excluded when no underlying disk was found - -To see *all* filesystems of your system, do `lfs --all`: - -![screen](img/rows-all.png) - -This list can be quite big with virtual file systems, docker use, etc. - -## Current filesystem - -If you're only interested in the device on which some file is, give the path as argument. - -For example, for the current device, use `lfs .`: - -![screen](img/rows-current.png) - -## Sort +# Sort With the `--sort` launch argument, shortened as `-s`, you can specify the order of displayed rows. diff --git a/website/mkdocs.yml b/website/mkdocs.yml index 0b12175..6c728bf 100644 --- a/website/mkdocs.yml +++ b/website/mkdocs.yml @@ -9,6 +9,7 @@ nav: - Install: install.md - Table: table.md - JSON: json.md + - Filters: filters.md - Community: community.md extra_css: |