Skip to content

Commit

Permalink
fix: fix self uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Feb 4, 2024
1 parent b265484 commit 057b1f0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
default-members = ["goup"]

[workspace.package]
version = "0.5.0"
version = "0.6.0"
authors = ["thinkgo <[email protected]>"]
edition = "2021"
rust-version = "1.70.0"
Expand Down
2 changes: 1 addition & 1 deletion goup-downloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository.workspace =true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
goup-version = {path = "../goup-version", version = "0.5"}
goup-version = {path = "../goup-version", version = "0.6"}
anyhow = "1.0"
dirs = "5.0"
regex = "1.10"
Expand Down
15 changes: 13 additions & 2 deletions goup-version/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub fn archive_url(archive_filename: &str) -> (String, String) {
}

// go_version_archive_url returns the zip or tar.gz URL of the given Go version.
#[deprecated(
since = "0.6.0",
note = "please use `list_upstream_go_versions` instead"
)]
pub fn go_version_archive_url(version: &str) -> String {
format!("{}/{}", go_download_base_url(), go_version_archive(version))
}
Expand All @@ -75,6 +79,8 @@ fn get_var_or_else(key: &str, op: impl FnOnce() -> String) -> String {

#[cfg(test)]
mod tests {
use crate::consts::{archive_sha256, archive_url, go_version_archive};

use super::{
go_download_base_url, go_host, go_source_git_url, go_source_upstream_git_url,
go_version_archive_url,
Expand Down Expand Up @@ -119,7 +125,12 @@ mod tests {
}

#[test]
fn test_archive_url() {
assert!(go_version_archive_url("1.21.5").starts_with("https://dl.google.com/go/1.21.5"))
fn test_archive() {
let archive_filename = go_version_archive("1.21.5");
assert!(archive_sha256(&archive_filename).ends_with(".sha256"));

let (archive_url, archive_sha256_url) = archive_url(&archive_filename);
assert!(archive_url.starts_with("https://dl.google.com/go/1.21.5"));
assert!(archive_sha256_url.starts_with("https://dl.google.com/go/1.21.5"))
}
}
4 changes: 2 additions & 2 deletions goup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ version_check = "0.9"
shadow-rs = "0.26"

[dependencies]
goup-version = {path = "../goup-version", version = "0.5"}
goup-downloader = {path = "../goup-downloader", version = "0.5"}
goup-version = {path = "../goup-version", version = "0.6"}
goup-downloader = {path = "../goup-downloader", version = "0.6"}

clap = {version = "4.4", features = ["derive", "env"]}
clap_complete = "4.4"
Expand Down
11 changes: 6 additions & 5 deletions goup/src/command/oneself.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap::CommandFactory;
use clap::Subcommand;
use dialoguer::theme::ColorfulTheme;
use dialoguer::Confirm;
use goup_version::Version;
use self_update::{backends::github::Update, cargo_crate_version};

use super::Cli;
Expand Down Expand Up @@ -49,19 +50,19 @@ impl Run for Oneself {
.with_prompt("Do you want to uninstall goup?")
.interact()?;
if confirmation {
// TODO...
log::warn!("Not implement real uninstall!",);
remove_goup_exe()?;
Version::remove_goup_home()?;
log::info!("Uninstall successful!");
} else {
log::info!("Cancelled");
log::info!("Cancelled!");
}
}
}
Ok(())
}
}

#[allow(dead_code)]
pub fn remove_goup_exe() -> Result<(), anyhow::Error> {
fn remove_goup_exe() -> Result<(), anyhow::Error> {
let exe = env::args().next().ok_or(anyhow!("Get exe path Failed"))?;
let exe = Path::new(&exe);
if exe.is_symlink() {
Expand Down

0 comments on commit 057b1f0

Please sign in to comment.