mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-01-05 23:59:09 +00:00
refactor: better windows UX
This commit is contained in:
parent
fd69ced633
commit
f2deb64f1c
1 changed files with 28 additions and 29 deletions
|
@ -1,5 +1,4 @@
|
||||||
use crate::cli::{bin_dir, version::update_bin_exe, HOME_DIR};
|
use crate::cli::{version::update_bin_exe, HOME_DIR};
|
||||||
use anyhow::Context;
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
|
@ -12,27 +11,37 @@ pub struct SelfInstallCommand {
|
||||||
|
|
||||||
impl SelfInstallCommand {
|
impl SelfInstallCommand {
|
||||||
pub fn run(self) -> anyhow::Result<()> {
|
pub fn run(self) -> anyhow::Result<()> {
|
||||||
let bin_dir = bin_dir()?;
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
if !self.skip_add_to_path {
|
{
|
||||||
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
|
if !self.skip_add_to_path {
|
||||||
|
use anyhow::Context;
|
||||||
|
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
|
||||||
|
|
||||||
let current_user = RegKey::predef(HKEY_CURRENT_USER);
|
let current_user = RegKey::predef(HKEY_CURRENT_USER);
|
||||||
let env = current_user
|
let env = current_user
|
||||||
.create_subkey("Environment")
|
.create_subkey("Environment")
|
||||||
.context("failed to open Environment key")?
|
.context("failed to open Environment key")?
|
||||||
.0;
|
.0;
|
||||||
let path: String = env.get_value("Path").context("failed to get Path value")?;
|
let path: String = env.get_value("Path").context("failed to get Path value")?;
|
||||||
|
|
||||||
let bin_dir = bin_dir.to_string_lossy();
|
let bin_dir = crate::cli::bin_dir()?;
|
||||||
|
let bin_dir = bin_dir.to_string_lossy();
|
||||||
|
|
||||||
let exists = path.split(';').any(|part| *part == bin_dir);
|
let exists = path.split(';').any(|part| *part == bin_dir);
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
let new_path = format!("{path};{bin_dir}");
|
let new_path = format!("{path};{bin_dir}");
|
||||||
env.set_value("Path", &new_path)
|
env.set_value("Path", &new_path)
|
||||||
.context("failed to set Path value")?;
|
.context("failed to set Path value")?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\nin order to allow binary exports as executables {}.\n\n{}",
|
||||||
|
format!("`~/{HOME_DIR}/bin` was added to PATH").green(),
|
||||||
|
"please restart your shell for this to take effect"
|
||||||
|
.yellow()
|
||||||
|
.bold()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
@ -40,16 +49,6 @@ impl SelfInstallCommand {
|
||||||
env!("CARGO_BIN_NAME").cyan(),
|
env!("CARGO_BIN_NAME").cyan(),
|
||||||
env!("CARGO_PKG_VERSION").yellow(),
|
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(),
|
|
||||||
"please restart your shell for this to take effect"
|
|
||||||
.yellow()
|
|
||||||
.bold()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -63,7 +62,7 @@ and then restart your shell.
|
||||||
"#,
|
"#,
|
||||||
env!("CARGO_BIN_NAME").cyan(),
|
env!("CARGO_BIN_NAME").cyan(),
|
||||||
env!("CARGO_PKG_VERSION").yellow(),
|
env!("CARGO_PKG_VERSION").yellow(),
|
||||||
format!(r#"export PATH="$PATH:~/{}/bin""#, HOME_DIR)
|
format!(r#"export PATH="$PATH:~/{HOME_DIR}/bin""#)
|
||||||
.bold()
|
.bold()
|
||||||
.green()
|
.green()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue