mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 06:02:36 +00:00
log: 📝 unique error output and update comment to fit config
This commit is contained in:
parent
cf9030cdf7
commit
9b237bbf9e
19 changed files with 36 additions and 67 deletions
|
@ -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
|
||||
|
|
|
@ -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::<Self>(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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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<Self> {
|
||||
// let mut blocks: Vec<Block> = 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),
|
||||
|
|
|
@ -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<Self> {
|
||||
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<Self> 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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Self> {
|
||||
match value {
|
||||
"fancy" => Some(Self::Fancy),
|
||||
"unicode" => Some(Self::Unicode),
|
||||
_ => {
|
||||
print_error!("icons->theme: {}", &value);
|
||||
print_error!("Bad icons.theme config, {}", &value);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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].
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue