Skip to content

Commit 0209f38

Browse files
committed
add geode sdk version command + fix template mod target version
1 parent 42d5de0 commit 0209f38

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "geode"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
authors = ["HJfod <[email protected]>", "Camila314 <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"

src/sdk.rs

+54-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
1+
use std::fmt::Display;
12
use std::io::{stdout, stdin, Write};
23
use std::path::{PathBuf, Path};
34
use crate::config::Config;
45
use clap::Subcommand;
56
use git2::build::RepoBuilder;
67
use git2::{FetchOptions, RemoteCallbacks, Repository};
78
use colored::Colorize;
9+
use std::fs;
810

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

14+
#[derive(Debug, Clone, PartialEq)]
15+
pub struct Version {
16+
pub major: u32,
17+
pub minor: u32,
18+
pub patch: u32,
19+
}
20+
21+
impl Version {
22+
pub fn to_string(&self) -> String {
23+
self.into()
24+
}
25+
}
26+
27+
impl From<String> for Version {
28+
fn from(str: String) -> Self {
29+
let mut iter = str.split(".");
30+
let (major, minor, patch) = (
31+
iter.next().and_then(|n| n.parse::<u32>().ok()).nice_unwrap("Invalid major part in version"),
32+
iter.next().and_then(|n| n.parse::<u32>().ok()).nice_unwrap("Invalid minor part in version"),
33+
iter.next().and_then(|n| n.parse::<u32>().ok()).nice_unwrap("Invalid patch part in version")
34+
);
35+
Version { major, minor, patch }
36+
}
37+
}
38+
39+
impl From<&Version> for String {
40+
fn from(ver: &Version) -> Self {
41+
format!("v{}.{}.{}", ver.major, ver.minor, ver.patch)
42+
}
43+
}
44+
45+
impl Display for Version {
46+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47+
f.write_fmt(format_args!("v{}.{}.{}", self.major, self.minor, self.patch))
48+
}
49+
}
50+
1251
#[derive(Subcommand, Debug)]
1352
pub enum Sdk {
1453
/// Install SDK
@@ -32,7 +71,10 @@ pub enum Sdk {
3271
/// Set update branch to stable
3372
#[clap(conflicts_with("nightly"))]
3473
stable: bool
35-
}
74+
},
75+
76+
/// Get SDK version
77+
Version,
3678
}
3779

3880
fn uninstall(config: &mut Config) -> bool {
@@ -161,6 +203,14 @@ fn update(config: &mut Config, nightly: bool, stable: bool) {
161203
}
162204
}
163205

206+
pub fn get_version(config: &mut Config) -> Version {
207+
Version::from(
208+
fs::read_to_string(
209+
config.sdk_path.as_ref().nice_unwrap("SDK not installed!").join("VERSION")
210+
).nice_unwrap("Unable to read SDK version, make sure you are using SDK v0.4.2 or later")
211+
)
212+
}
213+
164214
pub fn subcommand(config: &mut Config, cmd: Sdk) {
165215
match cmd {
166216
Sdk::Install { reinstall, path } => {
@@ -179,6 +229,7 @@ pub fn subcommand(config: &mut Config, cmd: Sdk) {
179229
install(config, path.unwrap_or(default_path));
180230
},
181231
Sdk::Uninstall => { uninstall(config); },
182-
Sdk::Update { nightly, stable } => update(config, nightly, stable)
232+
Sdk::Update { nightly, stable } => update(config, nightly, stable),
233+
Sdk::Version => info!("Geode SDK version: {}", get_version(config))
183234
}
184-
}
235+
}

src/template.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use serde_json::json;
88
use serde::Serialize;
99
use crate::{fail, fatal, warn, info, done};
1010
use crate::config::Config;
11+
use crate::sdk::get_version;
1112

1213
fn create_template(
14+
config: &mut Config,
1315
project_location: PathBuf,
1416
name: String,
1517
version: String,
@@ -56,7 +58,7 @@ fn create_template(
5658

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

133135
create_template(
136+
config,
134137
final_location,
135138
final_name,
136139
final_version,

0 commit comments

Comments
 (0)