refactor: better windows UX

This commit is contained in:
daimond113 2024-08-27 19:49:52 +02:00
parent fd69ced633
commit f2deb64f1c
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C

View file

@ -1,5 +1,4 @@
use crate::cli::{bin_dir, version::update_bin_exe, HOME_DIR};
use anyhow::Context;
use crate::cli::{version::update_bin_exe, HOME_DIR};
use clap::Args;
use colored::Colorize;
#[derive(Debug, Args)]
@ -12,10 +11,10 @@ pub struct SelfInstallCommand {
impl SelfInstallCommand {
pub fn run(self) -> anyhow::Result<()> {
let bin_dir = bin_dir()?;
#[cfg(windows)]
{
if !self.skip_add_to_path {
use anyhow::Context;
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
let current_user = RegKey::predef(HKEY_CURRENT_USER);
@ -25,6 +24,7 @@ impl SelfInstallCommand {
.0;
let path: String = env.get_value("Path").context("failed to get Path value")?;
let bin_dir = crate::cli::bin_dir()?;
let bin_dir = bin_dir.to_string_lossy();
let exists = path.split(';').any(|part| *part == bin_dir);
@ -33,15 +33,7 @@ impl SelfInstallCommand {
let new_path = format!("{path};{bin_dir}");
env.set_value("Path", &new_path)
.context("failed to set Path value")?;
}
println!(
"installed {} {}!",
env!("CARGO_BIN_NAME").cyan(),
env!("CARGO_PKG_VERSION").yellow(),
);
if !exists {
println!(
"\nin order to allow binary exports as executables {}.\n\n{}",
format!("`~/{HOME_DIR}/bin` was added to PATH").green(),
@ -52,6 +44,13 @@ impl SelfInstallCommand {
}
}
println!(
"installed {} {}!",
env!("CARGO_BIN_NAME").cyan(),
env!("CARGO_PKG_VERSION").yellow(),
);
}
#[cfg(unix)]
{
println!(
@ -63,7 +62,7 @@ and then restart your shell.
"#,
env!("CARGO_BIN_NAME").cyan(),
env!("CARGO_PKG_VERSION").yellow(),
format!(r#"export PATH="$PATH:~/{}/bin""#, HOME_DIR)
format!(r#"export PATH="$PATH:~/{HOME_DIR}/bin""#)
.bold()
.green()
);