Skip to content

Commit

Permalink
begin implementing arbitrary version for geode sdk update
Browse files Browse the repository at this point in the history
doesnt work atm because switch_to_ref is broken!
  • Loading branch information
matcool committed Oct 3, 2023
1 parent affe1de commit f9ab16b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ struct GithubReleaseResponse {
assets: Vec<GithubReleaseAsset>,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum Branch {
Nightly,
Stable,
}

fn download_url(
url: String,
file_name: &PathBuf,
Expand Down Expand Up @@ -76,9 +70,8 @@ pub enum Sdk {

/// Update SDK
Update {
/// Set update branch
#[clap(value_enum)]
branch: Option<Branch>,
/// Set update branch, can be nightly, stable, or any specific version
branch: Option<String>,
},

/// Change SDK path.
Expand Down Expand Up @@ -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<Branch>) {
fn update(config: &mut Config, branch: Option<String>) {
// 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");
Expand Down Expand Up @@ -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<Version> = None;
Expand Down
4 changes: 4 additions & 0 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Config {
pub profiles: Vec<RefCell<Profile>>,
pub default_developer: Option<String>,
pub sdk_nightly: bool,
pub sdk_version: Option<String>,
#[serde(flatten)]
other: HashMap<String, Value>,
}
Expand Down Expand Up @@ -80,6 +81,7 @@ impl OldConfig {
profiles,
default_developer: self.default_developer.to_owned(),
sdk_nightly: false,
sdk_version: None,
other: HashMap::new(),
}
}
Expand Down Expand Up @@ -205,6 +207,7 @@ impl Config {
profiles: Vec::new(),
default_developer: None,
sdk_nightly: false,
sdk_version: None,
other: HashMap::<String, Value>::new(),
};
}
Expand All @@ -219,6 +222,7 @@ impl Config {
profiles: Vec::new(),
default_developer: None,
sdk_nightly: false,
sdk_version: None,
other: HashMap::<String, Value>::new(),
}
} else {
Expand Down

0 comments on commit f9ab16b

Please sign in to comment.