mirror of
https://github.com/starship/starship.git
synced 2024-11-22 00:04:05 +01:00
refactor: bump msrv to remove once-cell, improve logger test & handle clippy warnings (#6315)
* refactor: replace `once_cell`-crate with stdlib * test(logger): make log cleanup-test cross-platform * chore: handle clippy warnings * build(deps): update dependency dprint/dprint-plugin-toml to v0.6.3 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
parent
22c6c5201d
commit
a5631a17dd
@ -28,6 +28,6 @@
|
|||||||
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.93.0/plugin.wasm",
|
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.93.0/plugin.wasm",
|
||||||
"https://github.com/dprint/dprint-plugin-json/releases/download/0.19.3/plugin.wasm",
|
"https://github.com/dprint/dprint-plugin-json/releases/download/0.19.3/plugin.wasm",
|
||||||
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.17.8/plugin.wasm",
|
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.17.8/plugin.wasm",
|
||||||
"https://github.com/dprint/dprint-plugin-toml/releases/download/0.6.2/plugin.wasm"
|
"https://github.com/dprint/dprint-plugin-toml/releases/download/0.6.3/plugin.wasm"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2762,7 +2762,6 @@ dependencies = [
|
|||||||
"nix",
|
"nix",
|
||||||
"notify-rust",
|
"notify-rust",
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"once_cell",
|
|
||||||
"open",
|
"open",
|
||||||
"os_info",
|
"os_info",
|
||||||
"path-slash",
|
"path-slash",
|
||||||
|
@ -23,7 +23,7 @@ license = "ISC"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/starship/starship"
|
repository = "https://github.com/starship/starship"
|
||||||
# Note: MSRV is only intended as a hint, and only the latest version is officially supported in starship.
|
# Note: MSRV is only intended as a hint, and only the latest version is officially supported in starship.
|
||||||
rust-version = "1.76"
|
rust-version = "1.80"
|
||||||
description = """
|
description = """
|
||||||
The minimal, blazing-fast, and infinitely customizable prompt for any shell! ☄🌌️
|
The minimal, blazing-fast, and infinitely customizable prompt for any shell! ☄🌌️
|
||||||
"""
|
"""
|
||||||
@ -56,7 +56,6 @@ log = { version = "0.4.22", features = ["std"] }
|
|||||||
# see: https://github.com/NixOS/nixpkgs/issues/160876
|
# see: https://github.com/NixOS/nixpkgs/issues/160876
|
||||||
notify-rust = { version = "4.11.3", optional = true }
|
notify-rust = { version = "4.11.3", optional = true }
|
||||||
nu-ansi-term = "0.50.1"
|
nu-ansi-term = "0.50.1"
|
||||||
once_cell = "1.20.2"
|
|
||||||
open = "5.3.0"
|
open = "5.3.0"
|
||||||
# update os module config and tests when upgrading os_info
|
# update os module config and tests when upgrading os_info
|
||||||
os_info = "3.8.2"
|
os_info = "3.8.2"
|
||||||
|
@ -4,8 +4,6 @@ version = 2
|
|||||||
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
||||||
# output a note when they are encountered.
|
# output a note when they are encountered.
|
||||||
ignore = [
|
ignore = [
|
||||||
|
|
||||||
|
|
||||||
# { id = "RUSTSEC-0000-0000", reason = "" },
|
# { id = "RUSTSEC-0000-0000", reason = "" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ use gix::{
|
|||||||
sec::{self as git_sec, trust::DefaultForLevel},
|
sec::{self as git_sec, trust::DefaultForLevel},
|
||||||
state as git_state, Repository, ThreadSafeRepository,
|
state as git_state, Repository, ThreadSafeRepository,
|
||||||
};
|
};
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@ -25,6 +24,7 @@ use std::num::ParseIntError;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
|
use std::sync::OnceLock;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use terminal_size::terminal_size;
|
use terminal_size::terminal_size;
|
||||||
|
|
||||||
@ -44,13 +44,13 @@ pub struct Context<'a> {
|
|||||||
pub logical_dir: PathBuf,
|
pub logical_dir: PathBuf,
|
||||||
|
|
||||||
/// A struct containing directory contents in a lookup-optimized format.
|
/// A struct containing directory contents in a lookup-optimized format.
|
||||||
dir_contents: OnceCell<DirContents>,
|
dir_contents: OnceLock<Result<DirContents, std::io::Error>>,
|
||||||
|
|
||||||
/// Properties to provide to modules.
|
/// Properties to provide to modules.
|
||||||
pub properties: Properties,
|
pub properties: Properties,
|
||||||
|
|
||||||
/// Private field to store Git information for modules who need it
|
/// Private field to store Git information for modules who need it
|
||||||
repo: OnceCell<Repo>,
|
repo: OnceLock<Result<Repo, Box<gix::discover::Error>>>,
|
||||||
|
|
||||||
/// The shell the user is assumed to be running
|
/// The shell the user is assumed to be running
|
||||||
pub shell: Shell,
|
pub shell: Shell,
|
||||||
@ -166,8 +166,8 @@ impl<'a> Context<'a> {
|
|||||||
properties,
|
properties,
|
||||||
current_dir,
|
current_dir,
|
||||||
logical_dir,
|
logical_dir,
|
||||||
dir_contents: OnceCell::new(),
|
dir_contents: OnceLock::new(),
|
||||||
repo: OnceCell::new(),
|
repo: OnceLock::new(),
|
||||||
shell,
|
shell,
|
||||||
target,
|
target,
|
||||||
width,
|
width,
|
||||||
@ -286,9 +286,9 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Will lazily get repo root and branch when a module requests it.
|
/// Will lazily get repo root and branch when a module requests it.
|
||||||
pub fn get_repo(&self) -> Result<&Repo, Box<gix::discover::Error>> {
|
pub fn get_repo(&self) -> Result<&Repo, &gix::discover::Error> {
|
||||||
self.repo
|
self.repo
|
||||||
.get_or_try_init(|| -> Result<Repo, Box<gix::discover::Error>> {
|
.get_or_init(|| -> Result<Repo, Box<gix::discover::Error>> {
|
||||||
// custom open options
|
// custom open options
|
||||||
let mut git_open_opts_map =
|
let mut git_open_opts_map =
|
||||||
git_sec::trust::Mapping::<gix::open::Options>::default();
|
git_sec::trust::Mapping::<gix::open::Options>::default();
|
||||||
@ -359,17 +359,21 @@ impl<'a> Context<'a> {
|
|||||||
kind: repository.kind(),
|
kind: repository.kind(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.as_ref()
|
||||||
|
.map_err(std::convert::AsRef::as_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dir_contents(&self) -> Result<&DirContents, std::io::Error> {
|
pub fn dir_contents(&self) -> Result<&DirContents, &std::io::Error> {
|
||||||
self.dir_contents.get_or_try_init(|| {
|
self.dir_contents
|
||||||
let timeout = self.root_config.scan_timeout;
|
.get_or_init(|| {
|
||||||
DirContents::from_path_with_timeout(
|
let timeout = self.root_config.scan_timeout;
|
||||||
&self.current_dir,
|
DirContents::from_path_with_timeout(
|
||||||
Duration::from_millis(timeout),
|
&self.current_dir,
|
||||||
self.root_config.follow_symlinks,
|
Duration::from_millis(timeout),
|
||||||
)
|
self.root_config.follow_symlinks,
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_shell() -> Shell {
|
fn get_shell() -> Shell {
|
||||||
|
@ -303,10 +303,6 @@ impl<'a> StringFormatter<'a> {
|
|||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
FormatElement::TextGroup(textgroup) => {
|
FormatElement::TextGroup(textgroup) => {
|
||||||
let textgroup = TextGroup {
|
|
||||||
format: textgroup.format,
|
|
||||||
style: textgroup.style,
|
|
||||||
};
|
|
||||||
parse_textgroup(textgroup, variables, style_variables, context)
|
parse_textgroup(textgroup, variables, style_variables, context)
|
||||||
}
|
}
|
||||||
FormatElement::Variable(name) => variables
|
FormatElement::Variable(name) => variables
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use super::string_formatter::StringFormatterError;
|
use super::string_formatter::StringFormatterError;
|
||||||
use super::StringFormatter;
|
use super::StringFormatter;
|
||||||
use crate::segment;
|
use crate::segment;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use versions::Versioning;
|
use versions::Versioning;
|
||||||
|
|
||||||
pub struct VersionFormatter<'a> {
|
pub struct VersionFormatter<'a> {
|
||||||
@ -30,7 +30,7 @@ impl<'a> VersionFormatter<'a> {
|
|||||||
|
|
||||||
/// Formats a version structure into a readable string
|
/// Formats a version structure into a readable string
|
||||||
pub fn format(self, version: &'a str) -> Result<String, StringFormatterError> {
|
pub fn format(self, version: &'a str) -> Result<String, StringFormatterError> {
|
||||||
let parsed = Lazy::new(|| Versioning::new(version));
|
let parsed = LazyLock::new(|| Versioning::new(version));
|
||||||
let formatted = self
|
let formatted = self
|
||||||
.formatter
|
.formatter
|
||||||
.map(|variable| match variable {
|
.map(|variable| match variable {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::utils;
|
use crate::utils;
|
||||||
use log::{Level, LevelFilter, Metadata, Record};
|
use log::{Level, LevelFilter, Metadata, Record};
|
||||||
use nu_ansi_term::Color;
|
use nu_ansi_term::Color;
|
||||||
use once_cell::sync::OnceCell;
|
use std::sync::OnceLock;
|
||||||
use std::{
|
use std::{
|
||||||
cmp,
|
cmp,
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
@ -13,7 +13,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct StarshipLogger {
|
pub struct StarshipLogger {
|
||||||
log_file: OnceCell<Mutex<File>>,
|
log_file: OnceLock<Result<Mutex<File>, std::io::Error>>,
|
||||||
log_file_path: PathBuf,
|
log_file_path: PathBuf,
|
||||||
log_file_content: RwLock<HashSet<String>>,
|
log_file_content: RwLock<HashSet<String>>,
|
||||||
log_level: Level,
|
log_level: Level,
|
||||||
@ -101,7 +101,7 @@ impl Default for StarshipLogger {
|
|||||||
.map(std::string::ToString::to_string)
|
.map(std::string::ToString::to_string)
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
log_file: OnceCell::new(),
|
log_file: OnceLock::new(),
|
||||||
log_file_path: session_log_file,
|
log_file_path: session_log_file,
|
||||||
log_level: env::var("STARSHIP_LOG")
|
log_level: env::var("STARSHIP_LOG")
|
||||||
.map(|level| match level.to_ascii_lowercase().as_str() {
|
.map(|level| match level.to_ascii_lowercase().as_str() {
|
||||||
@ -174,7 +174,7 @@ impl log::Log for StarshipLogger {
|
|||||||
// Write warning messages to the log file
|
// Write warning messages to the log file
|
||||||
// If log level is error, only write error messages to the log file
|
// If log level is error, only write error messages to the log file
|
||||||
if record.level() <= cmp::min(Level::Warn, self.log_level) {
|
if record.level() <= cmp::min(Level::Warn, self.log_level) {
|
||||||
let log_file = match self.log_file.get_or_try_init(|| {
|
let log_file = match self.log_file.get_or_init(|| {
|
||||||
OpenOptions::new()
|
OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
@ -224,7 +224,7 @@ impl log::Log for StarshipLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self) {
|
fn flush(&self) {
|
||||||
if let Some(m) = self.log_file.get() {
|
if let Some(Ok(m)) = self.log_file.get() {
|
||||||
let result = match m.lock() {
|
let result = match m.lock() {
|
||||||
Ok(mut file) => file.flush(),
|
Ok(mut file) => file.flush(),
|
||||||
Err(err) => return eprintln!("Log file writer mutex was poisoned: {err:?}"),
|
Err(err) => return eprintln!("Log file writer mutex was poisoned: {err:?}"),
|
||||||
@ -246,7 +246,9 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::utils::read_file;
|
use crate::utils::read_file;
|
||||||
use log::Log;
|
use log::Log;
|
||||||
|
use std::fs::{File, FileTimes};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_log_to_file() -> io::Result<()> {
|
fn test_log_to_file() -> io::Result<()> {
|
||||||
@ -353,11 +355,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
|
||||||
fn test_cleanup() -> io::Result<()> {
|
fn test_cleanup() -> io::Result<()> {
|
||||||
use nix::sys::{stat::utimes, time::TimeVal};
|
|
||||||
use std::fs::File;
|
|
||||||
|
|
||||||
let log_dir = tempfile::tempdir()?;
|
let log_dir = tempfile::tempdir()?;
|
||||||
|
|
||||||
// Should not be deleted
|
// Should not be deleted
|
||||||
@ -379,6 +377,10 @@ mod test {
|
|||||||
}
|
}
|
||||||
fs::create_dir(&directory)?;
|
fs::create_dir(&directory)?;
|
||||||
|
|
||||||
|
let times = FileTimes::new()
|
||||||
|
.set_accessed(SystemTime::UNIX_EPOCH)
|
||||||
|
.set_modified(SystemTime::UNIX_EPOCH);
|
||||||
|
|
||||||
// Set all files except the new file to be older than 24 hours
|
// Set all files except the new file to be older than 24 hours
|
||||||
for file in &[
|
for file in &[
|
||||||
&non_matching_file,
|
&non_matching_file,
|
||||||
@ -386,10 +388,19 @@ mod test {
|
|||||||
&old_file,
|
&old_file,
|
||||||
&directory,
|
&directory,
|
||||||
] {
|
] {
|
||||||
utimes(file.as_path(), &TimeVal::new(0, 0), &TimeVal::new(0, 0))?;
|
let Ok(f) = File::open(file) else {
|
||||||
if let Ok(f) = File::open(file) {
|
panic!("Unable to open file {file:?}!")
|
||||||
f.sync_all()?;
|
};
|
||||||
}
|
|
||||||
|
match f.set_times(times) {
|
||||||
|
Err(err) if err.kind() == io::ErrorKind::PermissionDenied => {
|
||||||
|
// Ignore permission errors (e.g. on Windows)
|
||||||
|
eprintln!("Unable to set file times for {file:?}: {err:?}");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
other => other,
|
||||||
|
}?;
|
||||||
|
f.sync_all()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup_log_files(log_dir.path());
|
cleanup_log_files(log_dir.path());
|
||||||
|
@ -4,7 +4,7 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use once_cell::unsync::OnceCell;
|
use std::cell::OnceCell;
|
||||||
|
|
||||||
use super::{Context, Module, ModuleConfig};
|
use super::{Context, Module, ModuleConfig};
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ use crate::configs::c::CConfig;
|
|||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
use crate::formatter::VersionFormatter;
|
use crate::formatter::VersionFormatter;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
/// Creates a module with the current C compiler and version
|
/// Creates a module with the current C compiler and version
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
@ -25,7 +25,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
let c_compiler_info = Lazy::new(|| context.exec_cmds_return_first(config.commands));
|
let c_compiler_info = LazyLock::new(|| context.exec_cmds_return_first(config.commands));
|
||||||
|
|
||||||
formatter
|
formatter
|
||||||
.map_meta(|var, _| match var {
|
.map_meta(|var, _| match var {
|
||||||
|
@ -254,7 +254,7 @@ fn get_pinned_sdk_version(json: &str) -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_local_dotnet_files(context: &Context) -> Result<Vec<DotNetFile>, std::io::Error> {
|
fn get_local_dotnet_files<'a>(context: &'a Context) -> Result<Vec<DotNetFile>, &'a std::io::Error> {
|
||||||
Ok(context
|
Ok(context
|
||||||
.dir_contents()?
|
.dir_contents()?
|
||||||
.files()
|
.files()
|
||||||
|
@ -4,8 +4,8 @@ use crate::configs::elixir::ElixirConfig;
|
|||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
|
|
||||||
use crate::formatter::VersionFormatter;
|
use crate::formatter::VersionFormatter;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
/// Create a module with the current Elixir version
|
/// Create a module with the current Elixir version
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
@ -23,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions = Lazy::new(|| get_elixir_version(context));
|
let versions = LazyLock::new(|| get_elixir_version(context));
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use once_cell::sync::{Lazy, OnceCell};
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::{LazyLock, OnceLock};
|
||||||
|
|
||||||
use super::{Context, Module, ModuleConfig};
|
use super::{Context, Module, ModuleConfig};
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ type Account<'a> = (&'a str, Option<&'a str>);
|
|||||||
struct GcloudContext {
|
struct GcloudContext {
|
||||||
config_name: String,
|
config_name: String,
|
||||||
config_path: PathBuf,
|
config_path: PathBuf,
|
||||||
config: OnceCell<Option<Ini>>,
|
config: OnceLock<Option<Ini>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GcloudContext {
|
impl<'a> GcloudContext {
|
||||||
@ -94,7 +94,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let gcloud_context = GcloudContext::new(&config_name, &config_path);
|
let gcloud_context = GcloudContext::new(&config_name, &config_path);
|
||||||
let account: Lazy<Option<Account<'_>>, _> = Lazy::new(|| gcloud_context.get_account());
|
let account: LazyLock<Option<Account<'_>>, _> = LazyLock::new(|| gcloud_context.get_account());
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use once_cell::sync::OnceCell;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use super::{Context, Module, ModuleConfig};
|
use super::{Context, Module, ModuleConfig};
|
||||||
|
|
||||||
@ -135,8 +135,8 @@ struct GitStatusInfo<'a> {
|
|||||||
context: &'a Context<'a>,
|
context: &'a Context<'a>,
|
||||||
repo: &'a context::Repo,
|
repo: &'a context::Repo,
|
||||||
config: GitStatusConfig<'a>,
|
config: GitStatusConfig<'a>,
|
||||||
repo_status: OnceCell<Option<RepoStatus>>,
|
repo_status: OnceLock<Option<RepoStatus>>,
|
||||||
stashed_count: OnceCell<Option<usize>>,
|
stashed_count: OnceLock<Option<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GitStatusInfo<'a> {
|
impl<'a> GitStatusInfo<'a> {
|
||||||
@ -149,8 +149,8 @@ impl<'a> GitStatusInfo<'a> {
|
|||||||
context,
|
context,
|
||||||
repo,
|
repo,
|
||||||
config,
|
config,
|
||||||
repo_status: OnceCell::new(),
|
repo_status: OnceLock::new(),
|
||||||
stashed_count: OnceCell::new(),
|
stashed_count: OnceLock::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@ use crate::configs::go::GoConfig;
|
|||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
use crate::formatter::VersionFormatter;
|
use crate::formatter::VersionFormatter;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
/// Creates a module with the current Go version
|
/// Creates a module with the current Go version
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
@ -26,8 +26,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let golang_version =
|
let golang_version =
|
||||||
Lazy::new(|| parse_go_version(&context.exec_cmd("go", &["version"])?.stdout));
|
LazyLock::new(|| parse_go_version(&context.exec_cmd("go", &["version"])?.stdout));
|
||||||
let mod_version = Lazy::new(|| get_go_mod_version(context));
|
let mod_version = LazyLock::new(|| get_go_mod_version(context));
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
|
@ -270,10 +270,7 @@ mod tests {
|
|||||||
toml_config["hostname"]["aliases"]
|
toml_config["hostname"]["aliases"]
|
||||||
.as_table_mut()
|
.as_table_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert(
|
.insert(hostname, toml::Value::String("homeworld".to_string()));
|
||||||
hostname.clone(),
|
|
||||||
toml::Value::String("homeworld".to_string()),
|
|
||||||
);
|
|
||||||
let actual = ModuleRenderer::new("hostname")
|
let actual = ModuleRenderer::new("hostname")
|
||||||
.config(toml_config)
|
.config(toml_config)
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -3,8 +3,7 @@ use super::{Context, Module, ModuleConfig};
|
|||||||
use crate::configs::mojo::MojoConfig;
|
use crate::configs::mojo::MojoConfig;
|
||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use std::sync::LazyLock;
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
/// Creates a module with the current Mojo version
|
/// Creates a module with the current Mojo version
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
@ -22,7 +21,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let version_hash = Lazy::new(|| get_mojo_version(context));
|
let version_hash = LazyLock::new(|| get_mojo_version(context));
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
@ -35,11 +34,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.map(|variable| match variable {
|
||||||
"version" => match version_hash.deref() {
|
"version" => match &*version_hash {
|
||||||
Some((version, _)) => Some(Ok(version)),
|
Some((version, _)) => Some(Ok(version)),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
"hash" => match version_hash.deref() {
|
"hash" => match &*version_hash {
|
||||||
Some((_, Some(hash))) => Some(Ok(hash)),
|
Some((_, Some(hash))) => Some(Ok(hash)),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
@ -3,12 +3,12 @@ use super::{Context, Module, ModuleConfig};
|
|||||||
use crate::configs::nodejs::NodejsConfig;
|
use crate::configs::nodejs::NodejsConfig;
|
||||||
use crate::formatter::{StringFormatter, VersionFormatter};
|
use crate::formatter::{StringFormatter, VersionFormatter};
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
/// Creates a module with the current Node.js version
|
/// Creates a module with the current Node.js version
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
@ -30,12 +30,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let nodejs_version = Lazy::new(|| {
|
let nodejs_version = LazyLock::new(|| {
|
||||||
context
|
context
|
||||||
.exec_cmd("node", &["--version"])
|
.exec_cmd("node", &["--version"])
|
||||||
.map(|cmd| cmd.stdout)
|
.map(|cmd| cmd.stdout)
|
||||||
});
|
});
|
||||||
let engines_version = Lazy::new(|| get_engines_version(context));
|
let engines_version = LazyLock::new(|| get_engines_version(context));
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{Context, Module, ModuleConfig};
|
use super::{Context, Module, ModuleConfig};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use crate::configs::ocaml::OCamlConfig;
|
use crate::configs::ocaml::OCamlConfig;
|
||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
@ -29,7 +29,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let opam_switch: Lazy<Option<OpamSwitch>, _> = Lazy::new(|| get_opam_switch(context));
|
let opam_switch: LazyLock<Option<OpamSwitch>, _> = LazyLock::new(|| get_opam_switch(context));
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
|
@ -3,8 +3,8 @@ use super::{Context, Module, ModuleConfig};
|
|||||||
use crate::configs::raku::RakuConfig;
|
use crate::configs::raku::RakuConfig;
|
||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
use crate::formatter::VersionFormatter;
|
use crate::formatter::VersionFormatter;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
/// Creates a module with the current raku version
|
/// Creates a module with the current raku version
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
@ -21,7 +21,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions = Lazy::new(|| get_raku_version(context));
|
let versions = LazyLock::new(|| get_raku_version(context));
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
|
@ -12,7 +12,7 @@ use crate::formatter::{StringFormatter, VersionFormatter};
|
|||||||
use crate::utils::create_command;
|
use crate::utils::create_command;
|
||||||
use home::rustup_home;
|
use home::rustup_home;
|
||||||
|
|
||||||
use once_cell::sync::OnceCell;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use guess_host_triple::guess_host_triple;
|
use guess_host_triple::guess_host_triple;
|
||||||
|
|
||||||
@ -22,23 +22,23 @@ type ToolchainString = String;
|
|||||||
/// A struct to cache the output of any commands that need to be run.
|
/// A struct to cache the output of any commands that need to be run.
|
||||||
struct RustToolingEnvironmentInfo {
|
struct RustToolingEnvironmentInfo {
|
||||||
/// Rustup settings parsed from $HOME/.rustup/settings.toml
|
/// Rustup settings parsed from $HOME/.rustup/settings.toml
|
||||||
rustup_settings: OnceCell<RustupSettings>,
|
rustup_settings: OnceLock<RustupSettings>,
|
||||||
/// Rustc toolchain overrides as contained in the environment or files
|
/// Rustc toolchain overrides as contained in the environment or files
|
||||||
env_toolchain_override: OnceCell<Option<String>>,
|
env_toolchain_override: OnceLock<Option<String>>,
|
||||||
/// The output of `rustup rustc --version` with a fixed toolchain
|
/// The output of `rustup rustc --version` with a fixed toolchain
|
||||||
rustup_rustc_output: OnceCell<RustupRunRustcVersionOutcome>,
|
rustup_rustc_output: OnceLock<RustupRunRustcVersionOutcome>,
|
||||||
/// The output of running rustc -vV. Only called if rustup rustc fails or
|
/// The output of running rustc -vV. Only called if rustup rustc fails or
|
||||||
/// is unavailable.
|
/// is unavailable.
|
||||||
rustc_verbose_output: OnceCell<Option<(VersionString, ToolchainString)>>,
|
rustc_verbose_output: OnceLock<Option<(VersionString, ToolchainString)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustToolingEnvironmentInfo {
|
impl RustToolingEnvironmentInfo {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
rustup_settings: OnceCell::new(),
|
rustup_settings: OnceLock::new(),
|
||||||
env_toolchain_override: OnceCell::new(),
|
env_toolchain_override: OnceLock::new(),
|
||||||
rustup_rustc_output: OnceCell::new(),
|
rustup_rustc_output: OnceLock::new(),
|
||||||
rustc_verbose_output: OnceCell::new(),
|
rustc_verbose_output: OnceLock::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,9 +500,9 @@ impl RustupSettings {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::context::{Shell, Target};
|
use crate::context::{Shell, Target};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process::{ExitStatus, Output};
|
use std::process::{ExitStatus, Output};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -648,7 +648,7 @@ version = "12"
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::os::windows::process::ExitStatusExt as _;
|
use std::os::windows::process::ExitStatusExt as _;
|
||||||
|
|
||||||
static RUSTC_VERSION: Lazy<Output> = Lazy::new(|| Output {
|
static RUSTC_VERSION: LazyLock<Output> = LazyLock::new(|| Output {
|
||||||
status: ExitStatus::from_raw(0),
|
status: ExitStatus::from_raw(0),
|
||||||
stdout: b"rustc 1.34.0\n"[..].to_owned(),
|
stdout: b"rustc 1.34.0\n"[..].to_owned(),
|
||||||
stderr: vec![],
|
stderr: vec![],
|
||||||
@ -658,7 +658,7 @@ version = "12"
|
|||||||
RustupRunRustcVersionOutcome::RustcVersion("rustc 1.34.0\n".to_owned()),
|
RustupRunRustcVersionOutcome::RustcVersion("rustc 1.34.0\n".to_owned()),
|
||||||
);
|
);
|
||||||
|
|
||||||
static TOOLCHAIN_NAME: Lazy<Output> = Lazy::new(|| Output {
|
static TOOLCHAIN_NAME: LazyLock<Output> = LazyLock::new(|| Output {
|
||||||
status: ExitStatus::from_raw(1),
|
status: ExitStatus::from_raw(1),
|
||||||
stdout: vec![],
|
stdout: vec![],
|
||||||
stderr: b"error: toolchain 'channel-triple' is not installed\n"[..].to_owned(),
|
stderr: b"error: toolchain 'channel-triple' is not installed\n"[..].to_owned(),
|
||||||
@ -668,7 +668,7 @@ version = "12"
|
|||||||
RustupRunRustcVersionOutcome::ToolchainNotInstalled("channel-triple".to_owned()),
|
RustupRunRustcVersionOutcome::ToolchainNotInstalled("channel-triple".to_owned()),
|
||||||
);
|
);
|
||||||
|
|
||||||
static INVALID_STDOUT: Lazy<Output> = Lazy::new(|| Output {
|
static INVALID_STDOUT: LazyLock<Output> = LazyLock::new(|| Output {
|
||||||
status: ExitStatus::from_raw(0),
|
status: ExitStatus::from_raw(0),
|
||||||
stdout: b"\xc3\x28"[..].to_owned(),
|
stdout: b"\xc3\x28"[..].to_owned(),
|
||||||
stderr: vec![],
|
stderr: vec![],
|
||||||
@ -678,7 +678,7 @@ version = "12"
|
|||||||
RustupRunRustcVersionOutcome::Err,
|
RustupRunRustcVersionOutcome::Err,
|
||||||
);
|
);
|
||||||
|
|
||||||
static INVALID_STDERR: Lazy<Output> = Lazy::new(|| Output {
|
static INVALID_STDERR: LazyLock<Output> = LazyLock::new(|| Output {
|
||||||
status: ExitStatus::from_raw(1),
|
status: ExitStatus::from_raw(1),
|
||||||
stdout: vec![],
|
stdout: vec![],
|
||||||
stderr: b"\xc3\x28"[..].to_owned(),
|
stderr: b"\xc3\x28"[..].to_owned(),
|
||||||
@ -688,7 +688,7 @@ version = "12"
|
|||||||
RustupRunRustcVersionOutcome::Err,
|
RustupRunRustcVersionOutcome::Err,
|
||||||
);
|
);
|
||||||
|
|
||||||
static UNEXPECTED_FORMAT_OF_ERROR: Lazy<Output> = Lazy::new(|| Output {
|
static UNEXPECTED_FORMAT_OF_ERROR: LazyLock<Output> = LazyLock::new(|| Output {
|
||||||
status: ExitStatus::from_raw(1),
|
status: ExitStatus::from_raw(1),
|
||||||
stdout: vec![],
|
stdout: vec![],
|
||||||
stderr: b"error:"[..].to_owned(),
|
stderr: b"error:"[..].to_owned(),
|
||||||
|
@ -5,18 +5,18 @@ use crate::{
|
|||||||
utils::{create_command, CommandOutput},
|
utils::{create_command, CommandOutput},
|
||||||
};
|
};
|
||||||
use log::{Level, LevelFilter};
|
use log::{Level, LevelFilter};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::LazyLock;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
static FIXTURE_DIR: Lazy<PathBuf> =
|
static FIXTURE_DIR: LazyLock<PathBuf> =
|
||||||
Lazy::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/test/fixtures/"));
|
LazyLock::new(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/test/fixtures/"));
|
||||||
|
|
||||||
static GIT_FIXTURE: Lazy<PathBuf> = Lazy::new(|| FIXTURE_DIR.join("git-repo.bundle"));
|
static GIT_FIXTURE: LazyLock<PathBuf> = LazyLock::new(|| FIXTURE_DIR.join("git-repo.bundle"));
|
||||||
static HG_FIXTURE: Lazy<PathBuf> = Lazy::new(|| FIXTURE_DIR.join("hg-repo.bundle"));
|
static HG_FIXTURE: LazyLock<PathBuf> = LazyLock::new(|| FIXTURE_DIR.join("hg-repo.bundle"));
|
||||||
|
|
||||||
static LOGGER: Once = Once::new();
|
static LOGGER: Once = Once::new();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user