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

bin: show update script for linux/macos #853

Merged
merged 2 commits into from
Dec 20, 2024
Merged
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
61 changes: 42 additions & 19 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +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());
if path.display().to_string().contains("\\Winget\\") {
info!(
"HEMTT is installed via winget, run `winget upgrade hemtt` to update"
);
}
}
}
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 @@ -219,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
Loading