Skip to content

Commit

Permalink
break out, refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Dec 19, 2024
1 parent 733645a commit 3f1250f
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,7 @@ pub fn execute(cli: &Cli) -> Result<(), Error> {
std::env::set_current_dir(dir).expect("Failed to set current directory");
}

if !is_ci() {
match update::check() {
Ok(Some(version)) => {
info!("HEMTT {version} is available, please update");
if let Ok(path) = std::env::current_exe() {
trace!("HEMTT is installed at: {}", path.display());
let os = std::env::consts::OS;

let (message, filter) = match os {
"windows" => (
"HEMTT is installed via winget, run `winget upgrade hemtt` to update",
"\\Winget\\".to_string()
),
_ => (
"HEMTT is installed in home directory, run `curl -sSf https://hemtt.dev/install.sh | sh` to update", {
let mut default = dirs::home_dir().expect("home directory exists");
if os != "macos" {
default = default.join(".local")
};

default.join("bin").display().to_string()
}
),
};

if path.display().to_string().contains(&filter) {
info!(message)
}
}
}
Err(e) => {
error!("Failed to check for updates: {e}");
}
_ => {}
}
}
check_for_update();

trace!("version: {}", env!("HEMTT_VERSION"));
trace!("platform: {}", std::env::consts::OS);
Expand Down Expand Up @@ -236,6 +201,47 @@ pub fn is_ci() -> bool {
false
}

fn check_for_update() {
if is_ci() {
return;
}
match update::check() {
Ok(Some(version)) => {
info!("HEMTT {version} is available, please update");
}
Err(e) => {
error!("Failed to check for updates: {e}");
return;
}
_ => return,
}
let Ok(path) = std::env::current_exe() else {
return;
};
trace!("HEMTT is installed at: {}", path.display());
let os = std::env::consts::OS;
let (message, filter) = match os {
"windows" => (
"HEMTT is installed via winget, run `winget upgrade hemtt` to update",
"\\Winget\\".to_string()
),
"linux" | "macos" => (
"HEMTT is installed in home directory, run `curl -sSf https://hemtt.dev/install.sh | sh` to update", {
let mut home = dirs::home_dir().expect("home directory exists");
if os == "linux" {
home = home.join(".local");
};
home.join("bin").display().to_string()
}
),
_ => return,
};

if path.display().to_string().contains(&filter) {
info!(message);
}
}

#[derive(clap::ValueEnum, Clone, Default, Debug, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum TableFormat {
Expand Down

0 comments on commit 3f1250f

Please sign in to comment.