print some more handy info in trace logs

This commit is contained in:
Lynne Megido 2021-06-14 17:35:47 +10:00
parent 0278fe252e
commit bd1a2a3e3a
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 24 additions and 2 deletions

View file

@ -7,7 +7,8 @@ Dates are given in YYYY-MM-DD format.
- Fixed PowerShell output regression introduced in v0.2.13, whoops - Fixed PowerShell output regression introduced in v0.2.13, whoops
#### Other #### Other
- Nicer version output: `fif -V` reports "fif v0.3.2" (instead of just "fif 0.3.2" without the "v"), and `fif --version` - Nicer version output: `fif -V` reports "fif v0.3.2" (instead of just "fif 0.3.2" without the "v"), and `fif --version`
reports `fif v0.3.2 (XDG-Mime backend)`, or whatever backend you're using. reports `fif v0.3.2 (XDG-Mime backend)`, or whatever backend you're using
- fif's trace output now includes its version, backend, operating system, and architecture
### v0.3.1 (2021-07-06) ### v0.3.1 (2021-07-06)
#### Features #### Features

View file

@ -35,6 +35,7 @@ use crate::formats::{Format, PowerShell, Shell};
use crate::mime_db::MimeDb; use crate::mime_db::MimeDb;
use crate::parameters::{OutputFormat, ScanOpts}; use crate::parameters::{OutputFormat, ScanOpts};
use std::collections::BTreeSet; use std::collections::BTreeSet;
use crate::utils::{clap_long_version, os_name};
mod findings; mod findings;
mod formats; mod formats;
@ -71,7 +72,7 @@ fn main() {
// .target(env_logger::Target::Stdout) // log to stdout rather than stderr // .target(env_logger::Target::Stdout) // log to stdout rather than stderr
.init(); .init();
// trace!("fif {}", CLAP_LONG_VERSION.get().unwrap()); trace!("fif {}, running on {} {}", clap_long_version(), std::env::consts::ARCH, os_name());
trace!("Initialise mimetype database"); trace!("Initialise mimetype database");
init_db(); init_db();

View file

@ -30,3 +30,23 @@ pub fn clap_version() -> &'static str { CLAP_VERSION.get_or_init(|| format!("v{}
pub fn clap_long_version() -> &'static str { pub fn clap_long_version() -> &'static str {
CLAP_LONG_VERSION.get_or_init(|| format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND)) CLAP_LONG_VERSION.get_or_init(|| format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND))
} }
/// Returns the name of the target operating system, like "Windows" or "macOS". Won't account for things like Wine or
/// Linuxulator.
pub fn os_name() -> String {
use std::env::consts::OS;
match OS {
"ios" => "iOS".into(),
"macos" => "macOS".into(),
"freebsd" => "FreeBSD".into(),
"openbsd" => "OpenBSD".into(),
"netbsd" => "NetBSD".into(),
"vxworks" => "VxWorks".into(),
_ => {
// generic case: return consts::OS with the first letter in uppercase ("linux" -> "Linux")
let mut os_upper = String::from(OS);
os_upper.get_mut(0..1).map(|first| first.make_ascii_uppercase());
os_upper
}
}
}