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
#### Other
- 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)
#### Features

View File

@ -35,6 +35,7 @@ use crate::formats::{Format, PowerShell, Shell};
use crate::mime_db::MimeDb;
use crate::parameters::{OutputFormat, ScanOpts};
use std::collections::BTreeSet;
use crate::utils::{clap_long_version, os_name};
mod findings;
mod formats;
@ -71,7 +72,7 @@ fn main() {
// .target(env_logger::Target::Stdout) // log to stdout rather than stderr
.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");
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 {
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
}
}
}