diff --git a/.gitignore b/.gitignore
index 88f2a34..85cf1b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ fif_*
!clippy.sh
cargo-timing*.html
todo.txt
-/pkg/*
\ No newline at end of file
+/pkg/*
+/out
diff --git a/.idea/fif.iml b/.idea/fif.iml
index 9c6974e..96be3b5 100644
--- a/.idea/fif.iml
+++ b/.idea/fif.iml
@@ -10,6 +10,7 @@
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b725665..611feef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,13 @@
Dates are given in YYYY-MM-DD format.
## v0.3
+### v0.3.2 (2021-mm-dd)
+#### Bugfixes
+- 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.
+
### v0.3.1 (2021-07-06)
#### Features
- Added JSON output support via `-o json`
diff --git a/src/formats.rs b/src/formats.rs
index 4cadb84..378b023 100644
--- a/src/formats.rs
+++ b/src/formats.rs
@@ -10,6 +10,7 @@ use cfg_if::cfg_if;
use snailquote::escape;
use crate::findings::ScanError;
+use crate::parameters::VERSION;
use crate::{Findings, BACKEND};
use itertools::Itertools;
@@ -49,9 +50,6 @@ macro_rules! writablesln {
};
}
-/// The current version of fif, as defined in Cargo.toml.
-const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
-
#[doc(hidden)]
type Entries<'a> = [Result, ScanError<'a>>];
diff --git a/src/parameters.rs b/src/parameters.rs
index e29f5e9..a6ad95a 100644
--- a/src/parameters.rs
+++ b/src/parameters.rs
@@ -1,8 +1,10 @@
//! [Clap] struct used to parse command line arguments.
use crate::string_type::String as StringType;
+use crate::BACKEND;
use cfg_if::cfg_if;
use clap::{AppSettings, Clap};
+use once_cell::sync::OnceCell;
use std::collections::BTreeSet;
use std::path::PathBuf;
@@ -14,6 +16,34 @@ cfg_if! {
}
}
+/// The current version of fif, as defined in Cargo.toml.
+pub const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
+
+// the version and long_version given to clap need to be a &str, but we want to use format!, which returns a String.
+// we can't just do something like `version = format!(...).as_str()`, because clap needs to know that the version will
+// live for a given lifetime, which we need to satisfy by making our String static. of course, you can't use format!
+// statically, so we need to use a OnceCell or similar to get around this.
+static CLAP_VERSION: OnceCell = OnceCell::new();
+static CLAP_LONG_VERSION: OnceCell = OnceCell::new();
+
+/// Sets [`CLAP_VERSION`] to be the version defined in Cargo.toml, prefixed with a v (e.g. "v0.3.1"), then returns it as
+/// a String.
+fn clap_version() -> &'static str {
+ CLAP_VERSION
+ .set(format!("v{}", VERSION.unwrap_or("???")))
+ .unwrap_or_default(); // it doesn't matter if CLAP_VERSION has already been set
+ CLAP_VERSION.get().unwrap().as_str()
+}
+
+/// Sets [`CLAP_LONG_VERSION`] to be similar to [`CLAP_VERSION`], followed by the chosen backend in parentheses (e.g.
+/// "v0.3.1 (XDG-Mime backend)"), then returns it as a String.
+fn clap_long_version() -> &'static str {
+ CLAP_LONG_VERSION
+ .set(format!("v{} ({} backend)", VERSION.unwrap_or("???"), BACKEND))
+ .unwrap_or_default();
+ CLAP_LONG_VERSION.get().unwrap().as_str()
+}
+
#[derive(Clap, PartialEq, Debug)]
pub enum OutputFormat {
/// A Bourne shell compatible script.
@@ -33,7 +63,8 @@ pub enum OutputFormat {
#[derive(Clap, Debug)]
#[clap(
- version = option_env!("CARGO_PKG_VERSION").unwrap_or("???"),
+ version = clap_version(),
+ long_version = clap_long_version(),
author = option_env!("CARGO_PKG_AUTHORS").unwrap_or("Lynnesbian"),
about = option_env!("CARGO_PKG_DESCRIPTION").unwrap_or("File Info Fixer"),
before_help = "Copyright © 2021 Lynnesbian under the GPL3 (or later) License.",