From 89ef4d6ed558f0fb5af3f163c1299af30d20d22f Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:39:56 -0500 Subject: [PATCH] fix: take out home directory paths from `mise dr` output (#2433) --- e2e/backend/test_cargo_binstall_token | 6 +++--- e2e/backend/test_cargo_compile_slow | 4 ++-- src/cli/doctor.rs | 2 ++ src/config/settings.rs | 4 +++- src/file.rs | 8 ++++++++ tests/cli/backend.rs | 10 +++++----- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/e2e/backend/test_cargo_binstall_token b/e2e/backend/test_cargo_binstall_token index 0006b4326..07813f6ff 100644 --- a/e2e/backend/test_cargo_binstall_token +++ b/e2e/backend/test_cargo_binstall_token @@ -11,10 +11,10 @@ chmod u+x ~/bin/cargo-binstall export PATH="$HOME/bin:$PATH" # This should reuse the existing GITHUB_TOKEN variable -assert_contains "GITHUB_TOKEN=foobar mise install -f cargo:eza@0.17.0 2>&1" "token=foobar" +assert_contains "GITHUB_TOKEN=foobar mise install -f cargo:eza@0.18.24 2>&1" "token=foobar" # This should use the GITHUB_API_TOKEN variable -assert_contains "GITHUB_API_TOKEN=foobar mise install -f cargo:eza@0.17.0 2>&1" "token=foobar" +assert_contains "GITHUB_API_TOKEN=foobar mise install -f cargo:eza@0.18.24 2>&1" "token=foobar" # This should prefer GITHUB_API_TOKEN -assert_contains "GITHUB_TOKEN=foobar GITHUB_API_TOKEN=barquz mise install -f cargo:eza@0.17.0 2>&1" "token=foobar" +assert_contains "GITHUB_TOKEN=foobar GITHUB_API_TOKEN=barquz mise install -f cargo:eza@0.18.24 2>&1" "token=foobar" diff --git a/e2e/backend/test_cargo_compile_slow b/e2e/backend/test_cargo_compile_slow index 168eecb87..f2c805c07 100644 --- a/e2e/backend/test_cargo_compile_slow +++ b/e2e/backend/test_cargo_compile_slow @@ -2,6 +2,6 @@ require_cmd cargo export MISE_CARGO_BINSTALL=0 -assert "mise x cargo:eza@0.17.0 -- eza -v" "eza - A modern, maintained replacement for ls -v0.17.0 [+git] +assert "mise x cargo:eza@0.18.24 -- eza -v" "eza - A modern, maintained replacement for ls +v0.18.24 [+git] https://github.com/eza-community/eza" diff --git a/src/cli/doctor.rs b/src/cli/doctor.rs index 9b066c63a..b264db5f0 100644 --- a/src/cli/doctor.rs +++ b/src/cli/doctor.rs @@ -331,11 +331,13 @@ static AFTER_LONG_HELP: &str = color_print::cstr!( ); fn section(header: &str, body: S) -> eyre::Result<()> { + let body = file::replace_paths_in_string(body); miseprintln!("\n{}: \n{}", style(header).bold(), indent_by(body, " ")); Ok(()) } fn inline_section(header: &str, body: S) -> eyre::Result<()> { + let body = file::replace_paths_in_string(body); miseprintln!("{}: {body}", style(header).bold()); Ok(()) } diff --git a/src/config/settings.rs b/src/config/settings.rs index 24b3c2cdd..bf9cee805 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -424,7 +424,9 @@ impl Settings { } pub fn as_dict(&self) -> eyre::Result { - Ok(self.to_string().parse()?) + let s = toml::to_string(self)?; + let table = toml::from_str(&s)?; + Ok(table) } } diff --git a/src/file.rs b/src/file.rs index 58d79f9b1..b4ce91bdc 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fmt::Display; use std::fs; use std::fs::File; #[cfg(unix)] @@ -162,6 +163,13 @@ pub fn display_path>(path: P) -> String { } } +/// replaces $HOME in a string with "~" and $PATH with "$PATH", generally used to clean up output +/// after it is rendered +pub fn replace_paths_in_string(input: S) -> String { + let home = env::HOME.to_string_lossy().to_string(); + input.to_string().replace(&home, "~") +} + /// replaces "~" with $HOME pub fn replace_path>(path: P) -> PathBuf { let path = path.as_ref(); diff --git a/tests/cli/backend.rs b/tests/cli/backend.rs index a579f636a..c9529a136 100644 --- a/tests/cli/backend.rs +++ b/tests/cli/backend.rs @@ -2,7 +2,7 @@ use crate::cli::prelude::*; use eyre::Result; const EXPECTED_EZA_OUTPUT: &str = "eza - A modern, maintained replacement for ls -v0.17.0 [+git] +v0.18.24 [+git] https://github.com/eza-community/eza "; @@ -12,13 +12,13 @@ https://github.com/eza-community/eza fn test_cargo_binstall() -> Result<()> { mise! { when!( - given!(args "rm", "cargo:eza@0.17.0"); + given!(args "rm", "cargo:eza@0.18.24"); should!(succeed) ), when!( given!(env_var "MISE_EXPERIMENTAL", "1"), given!(env_var "MISE_CARGO_BINSTALL", "1"), - given!(args "x", "cargo:eza@0.17.0", "--", "eza", "-v"); + given!(args "x", "cargo:eza@0.18.24", "--", "eza", "-v"); should!(output_exactly EXPECTED_EZA_OUTPUT), should!(succeed) ) @@ -31,12 +31,12 @@ fn test_cargo_binstall() -> Result<()> { fn test_cargo_local_build() -> Result<()> { mise! { when!( - given!(args "rm", "cargo:eza@0.17.0"); + given!(args "rm", "cargo:eza@0.18.24"); should!(succeed) ), when!( given!(env_var "MISE_EXPERIMENTAL", "1"), - given!(args "x", "cargo:eza@0.17.0", "--", "eza", "-v"); + given!(args "x", "cargo:eza@0.18.24", "--", "eza", "-v"); should!(output_exactly EXPECTED_EZA_OUTPUT), should!(succeed) )