From 9b237bbf9ea02d3f7156c70a9011a958e2b36232 Mon Sep 17 00:00:00 2001 From: zwPapEr Date: Sat, 28 Nov 2020 23:19:50 +0800 Subject: [PATCH] log: :memo: unique error output and update comment to fit config --- README.md | 8 ++++---- src/config_file.rs | 6 +++--- src/core.rs | 2 +- src/flags/blocks.rs | 25 ------------------------- src/flags/color.rs | 7 +++---- src/flags/date.rs | 6 +++--- src/flags/dereference.rs | 2 +- src/flags/display.rs | 2 +- src/flags/icons.rs | 7 +++---- src/flags/ignore_globs.rs | 7 +------ src/flags/indicators.rs | 2 +- src/flags/layout.rs | 2 +- src/flags/recursion.rs | 2 +- src/flags/size.rs | 4 ++-- src/flags/sorting.rs | 2 +- src/flags/symlinks.rs | 2 +- src/flags/total_size.rs | 2 +- src/main.rs | 3 ++- src/meta/mod.rs | 12 ++++++------ 19 files changed, 36 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 2095102..a2aba52 100644 --- a/README.md +++ b/README.md @@ -134,8 +134,7 @@ The [release page](https://github.com/Peltoche/lsd/releases) includes precompile ## Configuration `lsd` can be configured with a configuration file to set the default options. -Right now this only supports setting options that can be passed via the command -line options as well. +Check [Config file content](#config-file-content) for details. ### Config file location @@ -145,19 +144,20 @@ On non-Windows systems `lsd` follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) convention for the location of the configuration file. The configuration dir `lsd` uses is itself named `lsd`. In that directory it looks first for a file -called `config.yaml` and if it can't find one, a file named `config.yml`. +called `config.yaml`. For most people it should be enough to put their config file at `~/.config/lsd/config.yaml`. #### Windows -On Windows systems `lsd` only looks for the two files in one location: +On Windows systems `lsd` only looks for the `config.yaml` files in one location: `%APPDATA%\lsd\` ### Config file content This is an example config file with the default values and some additional remarks. + ```yaml # == Classic == # This is a shorthand to override some of the options to be backwards compatible diff --git a/src/config_file.rs b/src/config_file.rs index 2c240f7..f95cf52 100644 --- a/src/config_file.rs +++ b/src/config_file.rs @@ -97,7 +97,7 @@ impl Config { Err(e) => { match e.kind() { std::io::ErrorKind::NotFound => {} - _ => print_error!("bad config file: {}, {}\n", &file, e), + _ => print_error!("Can not open config file {}: {}.", &file, e), }; None } @@ -109,7 +109,7 @@ impl Config { match serde_yaml::from_str::(yaml) { Ok(c) => Some(c), Err(e) => { - print_error!("configuration file format error, {}\n\n", e); + print_error!("Configuration file format error, {}.", e); None } } @@ -126,7 +126,7 @@ impl Config { return Some(p); } } - Err(e) => print_error!("can not open config file: {}", e), + Err(e) => print_error!("Can not open config file: {}.", e), } None } diff --git a/src/core.rs b/src/core.rs index ce87310..ade6001 100644 --- a/src/core.rs +++ b/src/core.rs @@ -89,7 +89,7 @@ impl Core { let mut meta = match Meta::from_path(&path, self.flags.dereference.0) { Ok(meta) => meta, Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); + print_error!("{}: {}.", path.display(), err); continue; } }; diff --git a/src/flags/blocks.rs b/src/flags/blocks.rs index 55501f8..513d174 100644 --- a/src/flags/blocks.rs +++ b/src/flags/blocks.rs @@ -24,11 +24,6 @@ impl Blocks { /// `Blocks` does not contain a [Block] of variant [INode](Block::INode) yet, one is prepended /// to the returned value. /// - /// # Note - /// - /// The configuration file's Yaml is read in any case, to be able to check for errors and print - /// out warnings. - /// /// # Errors /// /// This errors if any of the [ArgMatches] parameter arguments causes [Block]'s implementation @@ -119,26 +114,6 @@ impl Blocks { } } - /// Get a [Blocks] from a [Yaml] array. The [Config] is used to log warnings about wrong values - /// in a Yaml. - // fn from_yaml_array(values: &[Yaml], config: &Config) -> Option { - // let mut blocks: Vec = vec![]; - // for array_el in values.iter() { - // match array_el { - // Yaml::String(value) => match Block::try_from(value.as_str()) { - // Ok(block) => blocks.push(block), - // Err(err) => config.print_warning(&err), - // }, - // _ => config.print_warning("The blocks config values have to be strings."), - // } - // } - // if blocks.is_empty() { - // None - // } else { - // Some(Self(blocks)) - // } - // } - /// This returns a Blocks struct for the long format. /// /// It contains the [Block]s [Permission](Block::Permission), [User](Block::User), diff --git a/src/flags/color.rs b/src/flags/color.rs index e33bbfa..5be3c47 100644 --- a/src/flags/color.rs +++ b/src/flags/color.rs @@ -36,8 +36,7 @@ pub enum ColorOption { } impl ColorOption { - /// Get a Color value from a [Yaml] string. The [Config] is used to log warnings about wrong - /// values in a Yaml. + /// Get a Color value from a [String]. fn from_str(value: &str) -> Option { match value { "always" => Some(Self::Always), @@ -45,7 +44,7 @@ impl ColorOption { "never" => Some(Self::Never), _ => { print_error!( - "color/when could only be one of auto, always and never, got {}", + "Config color.when could only be one of auto, always and never, got {}.", &value ); None @@ -67,7 +66,7 @@ impl Configurable for ColorOption { if let Some(color) = matches.value_of("color") { Self::from_str(&color) } else { - print_error!("bad color, should never happen"); + print_error!("Bad color args. This should not be reachable!"); None } } else { diff --git a/src/flags/date.rs b/src/flags/date.rs index d99bc89..be67d5a 100644 --- a/src/flags/date.rs +++ b/src/flags/date.rs @@ -1,4 +1,4 @@ -//! This module defines the [DateFlag]. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [DateFlag]. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use its [configure_from](Configurable::configure_from) method. use super::Configurable; @@ -23,7 +23,7 @@ impl DateFlag { match app::validate_time_format(&value) { Ok(()) => Some(Self::Formatted(value[1..].to_string())), _ => { - print_error!("Not a valid date format: {}", value); + print_error!("Not a valid date format: {}.", value); None } } @@ -36,7 +36,7 @@ impl DateFlag { "relative" => Some(Self::Relative), _ if value.starts_with('+') => Self::from_format_string(&value), _ => { - print_error!("Not a valid date value: {}", value); + print_error!("Not a valid date value: {}.", value); None } } diff --git a/src/flags/dereference.rs b/src/flags/dereference.rs index 80ee0b2..47877c4 100644 --- a/src/flags/dereference.rs +++ b/src/flags/dereference.rs @@ -1,4 +1,4 @@ -//! This module defines the [Dereference] flag. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [Dereference] flag. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use the [configure_from](Configurable::configure_from) method. use super::Configurable; diff --git a/src/flags/display.rs b/src/flags/display.rs index ae11cda..a23e7f9 100644 --- a/src/flags/display.rs +++ b/src/flags/display.rs @@ -1,4 +1,4 @@ -//! This module defines the [Display] flag. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [Display] flag. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use its [configure_from](Configurable::configure_from) method. use super::Configurable; diff --git a/src/flags/icons.rs b/src/flags/icons.rs index 9ce1551..f34aa0d 100644 --- a/src/flags/icons.rs +++ b/src/flags/icons.rs @@ -1,4 +1,4 @@ -//! This module defines the [IconOption]. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [IconOption]. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use its [configure_from](Configurable::configure_from) method. use super::Configurable; @@ -94,14 +94,13 @@ pub enum IconTheme { } impl IconTheme { - /// Get a value from a [Yaml] string. The [Config] is used to log warnings about wrong values - /// in a Yaml. + /// Get a value from a string. fn from_str(value: &str) -> Option { match value { "fancy" => Some(Self::Fancy), "unicode" => Some(Self::Unicode), _ => { - print_error!("icons->theme: {}", &value); + print_error!("Bad icons.theme config, {}", &value); None } } diff --git a/src/flags/ignore_globs.rs b/src/flags/ignore_globs.rs index c262029..6207b8a 100644 --- a/src/flags/ignore_globs.rs +++ b/src/flags/ignore_globs.rs @@ -1,4 +1,4 @@ -//! This module defines the [IgnoreGlobs]. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [IgnoreGlobs]. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use the [configure_from](IgnoreGlobs::configure_from) method. use crate::config_file::Config; @@ -17,11 +17,6 @@ impl IgnoreGlobs { /// - [from_config](IgnoreGlobs::from_config) /// - [Default::default] /// - /// # Note - /// - /// The configuration file's Yaml is read in any case, to be able to check for errors and print - /// out warnings. - /// /// # Errors /// /// If either of the [Glob::new] or [GlobSetBuilder.build] methods return an [Err]. diff --git a/src/flags/indicators.rs b/src/flags/indicators.rs index 0dfe482..5b68ebb 100644 --- a/src/flags/indicators.rs +++ b/src/flags/indicators.rs @@ -1,4 +1,4 @@ -//! This module defines the [Indicators] flag. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [Indicators] flag. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use the [configure_from](Configurable::configure_from) method. use super::Configurable; diff --git a/src/flags/layout.rs b/src/flags/layout.rs index 6b39b85..0b917bb 100644 --- a/src/flags/layout.rs +++ b/src/flags/layout.rs @@ -1,4 +1,4 @@ -//! This module defines the [Layout] flag. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [Layout] flag. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use its [configure_from](Configurable::configure_from) method. use crate::config_file::Config; diff --git a/src/flags/recursion.rs b/src/flags/recursion.rs index 0144bf5..a1b395d 100644 --- a/src/flags/recursion.rs +++ b/src/flags/recursion.rs @@ -1,4 +1,4 @@ -//! This module defines the [Recursion] options. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [Recursion] options. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use the [configure_from](Recursion::configure_from) method. use crate::config_file::Config; diff --git a/src/flags/size.rs b/src/flags/size.rs index e463a5a..bdd1e9b 100644 --- a/src/flags/size.rs +++ b/src/flags/size.rs @@ -1,4 +1,4 @@ -//! This module defines the [SizeFlag]. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [SizeFlag]. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use its [configure_from](Configurable::configure_from) method. use super::Configurable; @@ -29,7 +29,7 @@ impl SizeFlag { "bytes" => Some(Self::Bytes), _ => { print_error!( - "size can only be one of default, short or bytes, but got {}", + "Size can only be one of default, short or bytes, but got {}.", value ); None diff --git a/src/flags/sorting.rs b/src/flags/sorting.rs index c16a453..ac25e71 100644 --- a/src/flags/sorting.rs +++ b/src/flags/sorting.rs @@ -1,4 +1,4 @@ -//! This module defines the [Sorting] options. To set it up from [ArgMatches], a [Yaml] +//! This module defines the [Sorting] options. To set it up from [ArgMatches], a [Config] //! and its [Default] value, use the [configure_from](Sorting::configure_from) method. use super::Configurable; diff --git a/src/flags/symlinks.rs b/src/flags/symlinks.rs index 00fbf83..cc340c5 100644 --- a/src/flags/symlinks.rs +++ b/src/flags/symlinks.rs @@ -1,4 +1,4 @@ -//! This module defines the [NoSymlink] flag. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [NoSymlink] flag. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use the [configure_from](Configurable::configure_from) method. use super::Configurable; diff --git a/src/flags/total_size.rs b/src/flags/total_size.rs index 952c451..c2dc2e8 100644 --- a/src/flags/total_size.rs +++ b/src/flags/total_size.rs @@ -1,4 +1,4 @@ -//! This module defines the [TotalSize] flag. To set it up from [ArgMatches], a [Yaml] and its +//! This module defines the [TotalSize] flag. To set it up from [ArgMatches], a [Config] and its //! [Default] value, use the [configure_from](Configurable::configure_from) method. use super::Configurable; diff --git a/src/main.rs b/src/main.rs index 67c185e..3eaccd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,8 @@ macro_rules! print_error { let mut handle = stderr.lock(); // We can write on stderr, so we simply ignore the error and don't print // and stop with success. - let res = handle.write_all(std::format!($($arg)*).as_bytes()); + let res = handle.write_all(std::format!("lsd: {}\n\n", + std::format!($($arg)*)).as_bytes()); if res.is_err() { std::process::exit(0); } diff --git a/src/meta/mod.rs b/src/meta/mod.rs index 06bb120..a7f05f2 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -71,7 +71,7 @@ impl Meta { let entries = match self.path.read_dir() { Ok(entries) => entries, Err(err) => { - print_error!("lsd: {}: {}\n", self.path.display(), err); + print_error!("{}: {}.", self.path.display(), err); return Ok(None); } }; @@ -112,7 +112,7 @@ impl Meta { let mut entry_meta = match Self::from_path(&path, flags.dereference.0) { Ok(res) => res, Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); + print_error!("{}: {}.", path.display(), err); continue; } }; @@ -129,7 +129,7 @@ impl Meta { match entry_meta.recurse_into(depth - 1, &flags) { Ok(content) => entry_meta.content = content, Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); + print_error!("{}: {}.", path.display(), err); continue; } }; @@ -167,7 +167,7 @@ impl Meta { let metadata = match metadata { Ok(meta) => meta, Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); + print_error!("{}: {}.", path.display(), err); return 0; } }; @@ -180,7 +180,7 @@ impl Meta { let entries = match path.read_dir() { Ok(entries) => entries, Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); + print_error!("{}: {}.", path.display(), err); return size; } }; @@ -188,7 +188,7 @@ impl Meta { let path = match entry { Ok(entry) => entry.path(), Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); + print_error!("{}: {}.", path.display(), err); continue; } };