Compare commits
No commits in common. "f243cbba76e56226f08a84021447f262caa0c55a" and "10bf85ba0fcd23c6a05faed1825e8d4e2fc77c77" have entirely different histories.
f243cbba76
...
10bf85ba0f
8 changed files with 36 additions and 64 deletions
|
@ -6,9 +6,6 @@ Dates are given in YYYY-MM-DD format.
|
|||
#### Features
|
||||
- Added `--canonical-paths` flag for outputting canonical paths in output - for example,
|
||||
`mv /home/lynne/file.jpg /home/lynne/file.mp3` instead of the default `mv file.jpg file.mp3`
|
||||
#### Other
|
||||
- The `FIF_LOG` environment variable can now be used to set log level, in addition to `RUST_LOG`
|
||||
- Log output now uses abbreviated level names: For example, `[D] Message` instead of `[DEBUG] Message`
|
||||
|
||||
### v0.3.2 (2021-06-14)
|
||||
#### Bugfixes
|
||||
|
|
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -240,9 +240,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
|
|
@ -149,17 +149,16 @@ fif -qq ~/Downloads
|
|||
fif -qqq ~/Downloads
|
||||
```
|
||||
|
||||
The verbosity of the logging can also be modified by setting the environment variable `FIF_LOG` or `RUST_LOG` to `off`,
|
||||
`trace`, `debug`, `info`, `warn`, or `error`. Values set by `FIF_LOG` override `RUST_LOG`, and both override the `-v`
|
||||
and `-q` flags.
|
||||
The verbosity of the logging can also be modified by setting the environment variable `RUST_LOG` to `off`, `trace`,
|
||||
`debug`, `info`, `warn`, or `error`. Values set by `RUST_LOG` override the `-v` and `-q` flags.
|
||||
|
||||
For example:
|
||||
|
||||
```bash
|
||||
# show all levels except trace
|
||||
FIF_LOG=debug fif ~/Downloads
|
||||
RUST_LOG=debug fif ~/Downloads
|
||||
# only show errors
|
||||
FIF_LOG=error fif ~/Downloads
|
||||
RUST_LOG=error fif ~/Downloads
|
||||
```
|
||||
|
||||
The five logging levels are used as follows:
|
||||
|
|
|
@ -196,17 +196,7 @@ impl Format for Shell {
|
|||
}
|
||||
|
||||
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||
smart_write(
|
||||
f,
|
||||
writablesln![
|
||||
"cat <<- '???'",
|
||||
Newline,
|
||||
"No known extension for ",
|
||||
path,
|
||||
Newline,
|
||||
"???"
|
||||
],
|
||||
)
|
||||
smart_write(f, writablesln!["cat <<- '???'", Newline, "No known extension for ", path, Newline, "???"])
|
||||
}
|
||||
|
||||
fn unreadable<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||
|
@ -249,12 +239,7 @@ impl Format for PowerShell {
|
|||
// there doesn't seem to be a way to rename the file, prompting only if the target already exists.
|
||||
smart_write(
|
||||
f,
|
||||
writablesln![
|
||||
"Rename-Item -Verbose -Path ",
|
||||
from,
|
||||
" -NewName ",
|
||||
(to.file_name().unwrap())
|
||||
],
|
||||
writablesln!["Rename-Item -Verbose -Path ", from, " -NewName ", (to.file_name().unwrap())],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -24,7 +24,8 @@ use std::process::exit;
|
|||
|
||||
use cfg_if::cfg_if;
|
||||
use clap::Clap;
|
||||
use log::{debug, error, info, trace, warn, Level};
|
||||
use env_logger::Env;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use once_cell::sync::OnceCell;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
|
||||
|
@ -62,20 +63,13 @@ cfg_if! {
|
|||
fn main() {
|
||||
let args: parameters::Parameters = parameters::Parameters::parse();
|
||||
|
||||
let mut builder = env_logger::Builder::new();
|
||||
let mut builder = env_logger::Builder::from_env(Env::new().filter_or("RUST_LOG", args.default_verbosity()));
|
||||
|
||||
builder
|
||||
.filter_level(args.default_verbosity()) // set default log level
|
||||
.parse_default_env() // set log level from RUST_LOG
|
||||
.parse_env("FIF_LOG") // set log level from FIF_LOG
|
||||
.format(|buf, r| {
|
||||
let mut style = buf.default_level_style(r.level());
|
||||
// use bold for warnings and errors
|
||||
style.set_bold(r.level() <= Level::Warn);
|
||||
// only use the first character of the log level name
|
||||
let abbreviation = style.value(r.level().to_string().chars().next().unwrap());
|
||||
// e.g. [D] Debug message
|
||||
writeln!(buf, "[{}] {}", abbreviation, r.args())
|
||||
})
|
||||
// .format(|buf, r| writeln!(buf, "{} - {}", r.level(), r.args()))
|
||||
.format_module_path(false) // don't include module in logs, as it's not necessary
|
||||
.format_timestamp(None) // don't include timestamps (unnecessary, and the feature flag is disabled anyway)
|
||||
// .target(env_logger::Target::Stdout) // log to stdout rather than stderr
|
||||
.init();
|
||||
|
||||
trace!(
|
||||
|
@ -84,7 +78,7 @@ fn main() {
|
|||
std::env::consts::ARCH,
|
||||
os_name()
|
||||
);
|
||||
trace!("Initialising mimetype database");
|
||||
trace!("Initialise mimetype database");
|
||||
init_db();
|
||||
|
||||
debug!("Iterating directory: {:?}", args.dir);
|
||||
|
|
|
@ -109,12 +109,11 @@ pub struct Parameters {
|
|||
pub follow_symlinks: bool,
|
||||
|
||||
/// Output verbosity. Each additional `-v` increases verbosity.
|
||||
/// Can be overridden by FIF_LOG or RUST_LOG.
|
||||
/// Can be overridden by RUST_LOG.
|
||||
#[clap(short, long, parse(from_occurrences), group = "verbosity")]
|
||||
pub verbose: u8,
|
||||
|
||||
/// Output quietness. Each additional `-q` decreases verbosity.
|
||||
/// Can be overridden by FIF_LOG or RUST_LOG.
|
||||
#[clap(short, long, parse(from_occurrences), group = "verbosity")]
|
||||
pub quiet: u8,
|
||||
|
||||
|
@ -217,23 +216,21 @@ impl Parameters {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn default_verbosity(&self) -> log::LevelFilter {
|
||||
pub fn default_verbosity(&self) -> &'static str {
|
||||
#![allow(clippy::missing_const_for_fn)]
|
||||
// match was not permitted inside const functions until 1.46
|
||||
|
||||
use log::LevelFilter;
|
||||
|
||||
match self.quiet {
|
||||
0 => {
|
||||
match self.verbose {
|
||||
0 => LevelFilter::Info, // no verbosity flags specified
|
||||
1 => LevelFilter::Debug, // -v
|
||||
_ => LevelFilter::Trace, // -vv...
|
||||
0 => "info", // no verbosity flags specified
|
||||
1 => "debug", // -v
|
||||
_ => "trace", // -vv...
|
||||
}
|
||||
}
|
||||
1 => LevelFilter::Warn, // -q
|
||||
2 => LevelFilter::Error, // -qq
|
||||
_ => LevelFilter::Off, // -qqq...
|
||||
1 => "warn", // -q
|
||||
2 => "error", // -qq
|
||||
_ => "off", // -qqq...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -444,22 +444,21 @@ fn writables_is_correct() {
|
|||
#[test]
|
||||
/// Test various combinations of verbosity flags.
|
||||
fn verbosity() {
|
||||
use log::LevelFilter;
|
||||
assert!(
|
||||
Parameters::try_parse_from(&["fif", "-q", "-v"]).is_err(),
|
||||
"Failed to reject usage of both -q and -v!"
|
||||
);
|
||||
|
||||
let mut expected_results = HashMap::new();
|
||||
expected_results.insert("-qqqqqqqq", LevelFilter::Off);
|
||||
expected_results.insert("-qqq", LevelFilter::Off);
|
||||
expected_results.insert("-qq", LevelFilter::Error);
|
||||
expected_results.insert("-q", LevelFilter::Warn);
|
||||
expected_results.insert("-s", LevelFilter::Info);
|
||||
expected_results.insert("-v", LevelFilter::Debug);
|
||||
expected_results.insert("-vv", LevelFilter::Trace);
|
||||
expected_results.insert("-vvv", LevelFilter::Trace);
|
||||
expected_results.insert("-vvvvvvvv", LevelFilter::Trace);
|
||||
expected_results.insert("-qqqqqqqq", "off");
|
||||
expected_results.insert("-qqq", "off");
|
||||
expected_results.insert("-qq", "error");
|
||||
expected_results.insert("-q", "warn");
|
||||
expected_results.insert("-s", "info");
|
||||
expected_results.insert("-v", "debug");
|
||||
expected_results.insert("-vv", "trace");
|
||||
expected_results.insert("-vvv", "trace");
|
||||
expected_results.insert("-vvvvvvvv", "trace");
|
||||
|
||||
for (flags, level) in expected_results {
|
||||
assert_eq!(Parameters::parse_from(&["fif", flags]).default_verbosity(), level);
|
||||
|
|
|
@ -31,7 +31,8 @@ pub fn clap_long_version() -> &'static str {
|
|||
CLAP_LONG_VERSION.get_or_init(|| format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND))
|
||||
}
|
||||
|
||||
/// Returns the name of the target operating system with proper casing, like "Windows" or "macOS".
|
||||
/// Returns the name of the target operating system, like "Windows" or "macOS". Won't account for things like Wine or
|
||||
/// Linuxulator.
|
||||
#[allow(clippy::option_map_unit_fn)]
|
||||
pub fn os_name() -> String {
|
||||
use std::env::consts::OS;
|
||||
|
|
Loading…
Reference in a new issue