Skip to content

Commit

Permalink
add geode sdk version command + fix template mod target version
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Oct 11, 2022
1 parent 42d5de0 commit 0209f38
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "geode"
version = "1.0.1"
version = "1.0.2"
authors = ["HJfod <[email protected]>", "Camila314 <[email protected]>"]
edition = "2021"
build = "build.rs"
Expand Down
57 changes: 54 additions & 3 deletions src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
use std::fmt::Display;
use std::io::{stdout, stdin, Write};
use std::path::{PathBuf, Path};
use crate::config::Config;
use clap::Subcommand;
use git2::build::RepoBuilder;
use git2::{FetchOptions, RemoteCallbacks, Repository};
use colored::Colorize;
use std::fs;

use crate::{fail, warn, info, done};
use crate::NiceUnwrap;

#[derive(Debug, Clone, PartialEq)]
pub struct Version {
pub major: u32,
pub minor: u32,
pub patch: u32,
}

impl Version {
pub fn to_string(&self) -> String {
self.into()
}
}

impl From<String> for Version {
fn from(str: String) -> Self {
let mut iter = str.split(".");
let (major, minor, patch) = (
iter.next().and_then(|n| n.parse::<u32>().ok()).nice_unwrap("Invalid major part in version"),
iter.next().and_then(|n| n.parse::<u32>().ok()).nice_unwrap("Invalid minor part in version"),
iter.next().and_then(|n| n.parse::<u32>().ok()).nice_unwrap("Invalid patch part in version")
);
Version { major, minor, patch }
}
}

impl From<&Version> for String {
fn from(ver: &Version) -> Self {
format!("v{}.{}.{}", ver.major, ver.minor, ver.patch)
}
}

impl Display for Version {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("v{}.{}.{}", self.major, self.minor, self.patch))
}
}

#[derive(Subcommand, Debug)]
pub enum Sdk {
/// Install SDK
Expand All @@ -32,7 +71,10 @@ pub enum Sdk {
/// Set update branch to stable
#[clap(conflicts_with("nightly"))]
stable: bool
}
},

/// Get SDK version
Version,
}

fn uninstall(config: &mut Config) -> bool {
Expand Down Expand Up @@ -161,6 +203,14 @@ fn update(config: &mut Config, nightly: bool, stable: bool) {
}
}

pub fn get_version(config: &mut Config) -> Version {
Version::from(
fs::read_to_string(
config.sdk_path.as_ref().nice_unwrap("SDK not installed!").join("VERSION")
).nice_unwrap("Unable to read SDK version, make sure you are using SDK v0.4.2 or later")
)
}

pub fn subcommand(config: &mut Config, cmd: Sdk) {
match cmd {
Sdk::Install { reinstall, path } => {
Expand All @@ -179,6 +229,7 @@ pub fn subcommand(config: &mut Config, cmd: Sdk) {
install(config, path.unwrap_or(default_path));
},
Sdk::Uninstall => { uninstall(config); },
Sdk::Update { nightly, stable } => update(config, nightly, stable)
Sdk::Update { nightly, stable } => update(config, nightly, stable),
Sdk::Version => info!("Geode SDK version: {}", get_version(config))
}
}
}
5 changes: 4 additions & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use serde_json::json;
use serde::Serialize;
use crate::{fail, fatal, warn, info, done};
use crate::config::Config;
use crate::sdk::get_version;

fn create_template(
config: &mut Config,
project_location: PathBuf,
name: String,
version: String,
Expand Down Expand Up @@ -56,7 +58,7 @@ fn create_template(

// Default mod.json
let mod_json = json!({
"geode": "3", // TODO: fix
"geode": get_version(config).to_string(),
"version": version,
"id": id,
"name": name,
Expand Down Expand Up @@ -131,6 +133,7 @@ pub fn build_template(config: &mut Config, name: Option<String>, location: Optio
info!("Creating project {}", mod_id);

create_template(
config,
final_location,
final_name,
final_version,
Expand Down

0 comments on commit 0209f38

Please sign in to comment.