Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: take out home directory paths from mise dr output #2433

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions e2e/backend/test_cargo_binstall_token
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions e2e/backend/test_cargo_compile_slow
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,13 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
);

fn section<S: Display>(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<S: Display>(header: &str, body: S) -> eyre::Result<()> {
let body = file::replace_paths_in_string(body);
miseprintln!("{}: {body}", style(header).bold());
Ok(())
}
4 changes: 3 additions & 1 deletion src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ impl Settings {
}

pub fn as_dict(&self) -> eyre::Result<toml::Table> {
Ok(self.to_string().parse()?)
let s = toml::to_string(self)?;
let table = toml::from_str(&s)?;
Ok(table)
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt::Display;
use std::fs;
use std::fs::File;
#[cfg(unix)]
Expand Down Expand Up @@ -162,6 +163,13 @@ pub fn display_path<P: AsRef<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<S: Display>(input: S) -> String {
let home = env::HOME.to_string_lossy().to_string();
input.to_string().replace(&home, "~")
}

/// replaces "~" with $HOME
pub fn replace_path<P: AsRef<Path>>(path: P) -> PathBuf {
let path = path.as_ref();
Expand Down
10 changes: 5 additions & 5 deletions tests/cli/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
";

Expand All @@ -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)
)
Expand All @@ -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)
)
Expand Down
Loading