From f9ab16bdd4ae7324d268ed781e3aa81f7348a186 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:22:02 -0300 Subject: [PATCH] begin implementing arbitrary version for geode sdk update doesnt work atm because switch_to_ref is broken! --- src/sdk.rs | 37 +++++++++++++++++++++++-------------- src/util/config.rs | 4 ++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/sdk.rs b/src/sdk.rs index ad33815..86dc0bc 100644 --- a/src/sdk.rs +++ b/src/sdk.rs @@ -31,12 +31,6 @@ struct GithubReleaseResponse { assets: Vec, } -#[derive(clap::ValueEnum, Clone, Debug)] -pub enum Branch { - Nightly, - Stable, -} - fn download_url( url: String, file_name: &PathBuf, @@ -76,9 +70,8 @@ pub enum Sdk { /// Update SDK Update { - /// Set update branch - #[clap(value_enum)] - branch: Option, + /// Set update branch, can be nightly, stable, or any specific version + branch: Option, }, /// Change SDK path. @@ -277,18 +270,25 @@ fn install(config: &mut Config, path: PathBuf, force: bool) { info!("Use `geode sdk install-binaries` to install pre-built binaries"); } -fn update(config: &mut Config, branch: Option) { +fn update(config: &mut Config, branch: Option) { // Switch branch if necessary - match branch { - Some(Branch::Nightly) => { + match branch.as_ref().map(String::as_str) { + Some("nightly") => { info!("Switching to nightly"); config.sdk_nightly = true; + config.sdk_version = None; } - Some(Branch::Stable) => { + Some("stable") => { info!("Switching to stable"); config.sdk_nightly = false; + config.sdk_version = None; + } + Some(ver) => { + info!("Switching to {}", ver); + config.sdk_nightly = false; + config.sdk_version = Some(ver.into()); } - None => {} + _ => {} }; info!("Updating SDK"); @@ -363,6 +363,15 @@ fn switch_to_tag(config: &mut Config, repo: &Repository) { switch_to_ref(repo, "refs/heads/main"); info!("Switched to latest commit"); return; + } else if let Some(ver) = config.sdk_version.clone() { + let ref_str = format!("refs/tags/{ver}"); + if repo.find_reference(ref_str.as_str()).is_err() { + config.sdk_version = None; + fatal!("Unable to find tag {ver}"); + } + switch_to_ref(repo, ref_str.as_str()); + info!("Switched to {ver}"); + return; } let mut latest_version: Option = None; diff --git a/src/util/config.rs b/src/util/config.rs index 567f9db..0ee2052 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -24,6 +24,7 @@ pub struct Config { pub profiles: Vec>, pub default_developer: Option, pub sdk_nightly: bool, + pub sdk_version: Option, #[serde(flatten)] other: HashMap, } @@ -80,6 +81,7 @@ impl OldConfig { profiles, default_developer: self.default_developer.to_owned(), sdk_nightly: false, + sdk_version: None, other: HashMap::new(), } } @@ -205,6 +207,7 @@ impl Config { profiles: Vec::new(), default_developer: None, sdk_nightly: false, + sdk_version: None, other: HashMap::::new(), }; } @@ -219,6 +222,7 @@ impl Config { profiles: Vec::new(), default_developer: None, sdk_nightly: false, + sdk_version: None, other: HashMap::::new(), } } else {