nicer output for fif -V
and fif --version
This commit is contained in:
parent
95956f8e30
commit
f8dcdf8a3c
5 changed files with 43 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,4 +8,5 @@ fif_*
|
||||||
!clippy.sh
|
!clippy.sh
|
||||||
cargo-timing*.html
|
cargo-timing*.html
|
||||||
todo.txt
|
todo.txt
|
||||||
/pkg/*
|
/pkg/*
|
||||||
|
/out
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<excludeFolder url="file://$MODULE_DIR$/awful" />
|
<excludeFolder url="file://$MODULE_DIR$/awful" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.mypy_cache" />
|
<excludeFolder url="file://$MODULE_DIR$/.mypy_cache" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/pkg" />
|
<excludeFolder url="file://$MODULE_DIR$/pkg" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/out" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
Dates are given in YYYY-MM-DD format.
|
Dates are given in YYYY-MM-DD format.
|
||||||
|
|
||||||
## v0.3
|
## 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)
|
### v0.3.1 (2021-07-06)
|
||||||
#### Features
|
#### Features
|
||||||
- Added JSON output support via `-o json`
|
- Added JSON output support via `-o json`
|
||||||
|
|
|
@ -10,6 +10,7 @@ use cfg_if::cfg_if;
|
||||||
use snailquote::escape;
|
use snailquote::escape;
|
||||||
|
|
||||||
use crate::findings::ScanError;
|
use crate::findings::ScanError;
|
||||||
|
use crate::parameters::VERSION;
|
||||||
use crate::{Findings, BACKEND};
|
use crate::{Findings, BACKEND};
|
||||||
use itertools::Itertools;
|
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)]
|
#[doc(hidden)]
|
||||||
type Entries<'a> = [Result<Findings<'a>, ScanError<'a>>];
|
type Entries<'a> = [Result<Findings<'a>, ScanError<'a>>];
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
//! [Clap] struct used to parse command line arguments.
|
//! [Clap] struct used to parse command line arguments.
|
||||||
|
|
||||||
use crate::string_type::String as StringType;
|
use crate::string_type::String as StringType;
|
||||||
|
use crate::BACKEND;
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use clap::{AppSettings, Clap};
|
use clap::{AppSettings, Clap};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::path::PathBuf;
|
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<String> = OnceCell::new();
|
||||||
|
static CLAP_LONG_VERSION: OnceCell<String> = 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)]
|
#[derive(Clap, PartialEq, Debug)]
|
||||||
pub enum OutputFormat {
|
pub enum OutputFormat {
|
||||||
/// A Bourne shell compatible script.
|
/// A Bourne shell compatible script.
|
||||||
|
@ -33,7 +63,8 @@ pub enum OutputFormat {
|
||||||
|
|
||||||
#[derive(Clap, Debug)]
|
#[derive(Clap, Debug)]
|
||||||
#[clap(
|
#[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"),
|
author = option_env!("CARGO_PKG_AUTHORS").unwrap_or("Lynnesbian"),
|
||||||
about = option_env!("CARGO_PKG_DESCRIPTION").unwrap_or("File Info Fixer"),
|
about = option_env!("CARGO_PKG_DESCRIPTION").unwrap_or("File Info Fixer"),
|
||||||
before_help = "Copyright © 2021 Lynnesbian under the GPL3 (or later) License.",
|
before_help = "Copyright © 2021 Lynnesbian under the GPL3 (or later) License.",
|
||||||
|
|
Loading…
Reference in a new issue