Skip to content

Commit 16a26f2

Browse files
committed
make missing config be treated as a warning rather than an error +
add current exe path to config command output + update version to 0.2.1
1 parent 7e9d423 commit 16a26f2

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

Cargo.toml

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

lib/Cargo.toml

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

src/config.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::process::exit;
44
use std::fs;
55
use serde::{Deserialize, Serialize};
66
use directories::BaseDirs;
7+
use colored::*;
78

89
#[derive(Serialize, Deserialize, Clone)]
910
#[serde(rename_all = "kebab-case")]
@@ -17,14 +18,14 @@ pub struct Installation {
1718
pub struct Config {
1819
pub default_installation: usize,
1920
pub working_installation: Option<usize>,
20-
pub installations: Vec<Installation>,
21+
pub installations: Option<Vec<Installation>>,
2122
pub default_developer: Option<String>,
2223
}
2324

2425
static mut CONFIG: Config = Config {
2526
default_installation: 0,
2627
working_installation: None,
27-
installations: vec!(),
28+
installations: None,
2829
default_developer: None,
2930
};
3031

@@ -50,11 +51,17 @@ impl Config {
5051
let config_json = Config::data_dir().join("config.json");
5152
if !config_json.exists() {
5253
println!(
53-
"It seems you don't have Geode installed! \
54+
"{}{}{}{}",
55+
"WARNING: It seems you don't have Geode installed! \
5456
Please install Geode first using the official installer \
55-
(https://github.com/geode-sdk/installer/releases/latest)"
57+
(".yellow(),
58+
"https://github.com/geode-sdk/installer/releases/latest".cyan(),
59+
")".yellow(),
60+
"\nYou may still use the CLI, but be warned that certain \
61+
operations will cause crashes.\n".purple()
5662
);
57-
exit(1);
63+
fs::create_dir_all(Config::data_dir()).unwrap();
64+
return;
5865
}
5966
CONFIG = match serde_json::from_str(
6067
&fs::read_to_string(&config_json).unwrap()
@@ -65,13 +72,18 @@ impl Config {
6572
exit(1);
6673
}
6774
};
68-
if CONFIG.installations.len() == 0 {
75+
if CONFIG.installations.is_none() {
6976
println!(
70-
"It seems you don't have any installations of Geode! \
77+
"{}{}{}{}",
78+
"WARNING: It seems you don't have any installations of Geode! \
7179
Please install Geode first using the official installer \
72-
(https://github.com/geode-sdk/installer/releases/latest)"
80+
(".yellow(),
81+
"https://github.com/geode-sdk/installer/releases/latest".cyan(),
82+
")".yellow(),
83+
"\nYou may still use the CLI, but be warned that certain \
84+
operations will cause crashes.\n".purple()
7385
);
74-
exit(1);
86+
return;
7587
}
7688
if CONFIG.working_installation.is_none() {
7789
CONFIG.working_installation = Some(CONFIG.default_installation);
@@ -93,6 +105,8 @@ impl Config {
93105
}
94106

95107
pub fn work_inst() -> &'static Installation {
96-
&Config::get().installations[Config::get().working_installation.unwrap()]
108+
&Config::get().installations.as_ref().unwrap()[
109+
Config::get().working_installation.unwrap()
110+
]
97111
}
98112
}

src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn main() {
198198
Commands::Config { cwi, dev } => {
199199
let mut some_set = false;
200200
if cwi.is_some() {
201-
if cwi.unwrap() >= Config::get().installations.len() {
201+
if cwi.unwrap() >= Config::get().installations.as_ref().unwrap().len() {
202202
print_error!(
203203
"Provided index is higher than your \
204204
amount of installations!"
@@ -217,13 +217,15 @@ fn main() {
217217
println!(
218218
" == {} == \n\
219219
Version: {}\n\
220+
Path: {}\n\
220221
Default developer: {}\n\
221222
Data directory: {}\n\
222223
Selected Installation: {}\n\
223224
-> Path: {}\n\
224225
-> Loader Version: {}",
225226
GEODE_CLI_NAME.to_string().green(),
226227
GEODE_CLI_VERSION.to_string().yellow(),
228+
std::env::current_exe().unwrap().to_str().unwrap().cyan(),
227229
match Config::get().default_developer.as_ref() {
228230
Some(s) => s,
229231
None => "<none>"

0 commit comments

Comments
 (0)