use SmartStrings in more places
This commit is contained in:
parent
bddd6caeb2
commit
a800be63f7
2 changed files with 10 additions and 7 deletions
|
@ -7,12 +7,13 @@ use std::os::unix::ffi::OsStrExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
use itertools::{Either, Itertools};
|
||||||
use snailquote::escape;
|
use snailquote::escape;
|
||||||
|
|
||||||
use crate::findings::ScanError;
|
use crate::findings::ScanError;
|
||||||
use crate::utils::clap_long_version;
|
use crate::utils::clap_long_version;
|
||||||
use crate::Findings;
|
use crate::Findings;
|
||||||
use itertools::{Either, Itertools};
|
use crate::String;
|
||||||
|
|
||||||
/// A macro for creating an array of `Writable`s without needing to pepper your code with `into()`s.
|
/// A macro for creating an array of `Writable`s without needing to pepper your code with `into()`s.
|
||||||
/// # Usage
|
/// # Usage
|
||||||
|
@ -73,7 +74,7 @@ impl<'a> From<&'a OsStr> for Writable<'a> {
|
||||||
fn from(p: &'a OsStr) -> Writable<'a> { Writable::Path(p.as_ref()) }
|
fn from(p: &'a OsStr) -> Writable<'a> { Writable::Path(p.as_ref()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generated_by() -> String { format!("Generated by fif {}", clap_long_version()) }
|
fn generated_by() -> String { format!("Generated by fif {}", clap_long_version()).into() }
|
||||||
|
|
||||||
pub fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<()> {
|
pub fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<()> {
|
||||||
// ehhhh
|
// ehhhh
|
||||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -1,6 +1,8 @@
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
|
use crate::String;
|
||||||
|
|
||||||
/// The current version of fif, as defined in Cargo.toml.
|
/// The current version of fif, as defined in Cargo.toml.
|
||||||
pub const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
pub const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
@ -28,23 +30,23 @@ pub fn clap_version() -> &'static str { CLAP_VERSION.get_or_init(|| String::from
|
||||||
/// Sets [`CLAP_LONG_VERSION`] to be similar to [`CLAP_VERSION`], followed by the chosen backend in parentheses (e.g.
|
/// 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.
|
/// "v0.3.1 (XDG-Mime backend)"), then returns it as a String.
|
||||||
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).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the name of the target operating system with proper casing, like "Windows" or "macOS".
|
/// Returns the name of the target operating system with proper casing, like "Windows" or "macOS".
|
||||||
#[allow(clippy::option_map_unit_fn)]
|
#[allow(clippy::option_map_unit_fn)]
|
||||||
pub fn os_name() -> String {
|
pub fn os_name() -> String {
|
||||||
use std::env::consts::OS;
|
match std::env::consts::OS {
|
||||||
match OS {
|
// special cases: "ios" should not be capitalised into "Ios", for example
|
||||||
"ios" => "iOS".into(),
|
"ios" => "iOS".into(),
|
||||||
"macos" => "macOS".into(),
|
"macos" => "macOS".into(),
|
||||||
"freebsd" => "FreeBSD".into(),
|
"freebsd" => "FreeBSD".into(),
|
||||||
"openbsd" => "OpenBSD".into(),
|
"openbsd" => "OpenBSD".into(),
|
||||||
"netbsd" => "NetBSD".into(),
|
"netbsd" => "NetBSD".into(),
|
||||||
"vxworks" => "VxWorks".into(),
|
"vxworks" => "VxWorks".into(),
|
||||||
_ => {
|
os => {
|
||||||
// generic case: return consts::OS with the first letter in uppercase ("linux" -> "Linux")
|
// generic case: return consts::OS with the first letter in uppercase ("linux" -> "Linux")
|
||||||
let mut os_upper = String::from(OS);
|
let mut os_upper = String::from(os);
|
||||||
os_upper.get_mut(0..1).map(|first| first.make_ascii_uppercase());
|
os_upper.get_mut(0..1).map(|first| first.make_ascii_uppercase());
|
||||||
os_upper
|
os_upper
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue