Compare commits
2 commits
2f057425c3
...
712b95e24d
| Author | SHA1 | Date | |
|---|---|---|---|
| 712b95e24d | |||
| d383d8027c |
3 changed files with 47 additions and 3 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -1,6 +1,7 @@
|
||||||
mod models;
|
mod models;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
use crate::models::config::{Config, Mods, Server};
|
||||||
use crate::models::fabric::FabricVersions;
|
use crate::models::fabric::FabricVersions;
|
||||||
use crate::{
|
use crate::{
|
||||||
models::vanilla::{VanillaVersionDetail, VanillaVersionType, VanillaVersions},
|
models::vanilla::{VanillaVersionDetail, VanillaVersionType, VanillaVersions},
|
||||||
|
|
@ -32,7 +33,7 @@ struct Mcsm {
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Init { name: String },
|
Create { project_name: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
@ -40,9 +41,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let mcsm = Mcsm::parse();
|
let mcsm = Mcsm::parse();
|
||||||
|
|
||||||
match mcsm.command {
|
match mcsm.command {
|
||||||
Commands::Init { name: project_name } => {
|
Commands::Create { project_name } => {
|
||||||
tokio::fs::create_dir(&project_name).await?;
|
tokio::fs::create_dir_all(&project_name).await?;
|
||||||
std::env::set_current_dir(&project_name)?;
|
std::env::set_current_dir(&project_name)?;
|
||||||
|
let mut config_file = tokio::fs::File::create("mcsm.toml").await?;
|
||||||
|
|
||||||
let loaders = vec!["Vanilla", "Fabric"];
|
let loaders = vec!["Vanilla", "Fabric"];
|
||||||
let loader_index = Select::with_theme(&ColorfulTheme::default())
|
let loader_index = Select::with_theme(&ColorfulTheme::default())
|
||||||
|
|
@ -125,6 +127,18 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let config = Config {
|
||||||
|
server: Server {
|
||||||
|
version: release_version_names[version_index].to_string(),
|
||||||
|
loader: loaders[loader_index].to_string(),
|
||||||
|
loader_version: None,
|
||||||
|
},
|
||||||
|
mods: Mods {},
|
||||||
|
};
|
||||||
|
config_file
|
||||||
|
.write_all(toml::to_string(&config)?.as_bytes())
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
const URL: &str = "https://meta.fabricmc.net/v2/versions";
|
const URL: &str = "https://meta.fabricmc.net/v2/versions";
|
||||||
|
|
@ -196,6 +210,18 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let config = Config {
|
||||||
|
server: Server {
|
||||||
|
version: game_version,
|
||||||
|
loader: loaders[loader_index].to_string(),
|
||||||
|
loader_version: Some(loader_version),
|
||||||
|
},
|
||||||
|
mods: Mods {},
|
||||||
|
};
|
||||||
|
config_file
|
||||||
|
.write_all(toml::to_string(&config)?.as_bytes())
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
_ => return Err("Invalid selection".into()),
|
_ => return Err("Invalid selection".into()),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/models/config.rs
Normal file
17
src/models/config.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub server: Server,
|
||||||
|
pub mods: Mods,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct Server {
|
||||||
|
pub version: String,
|
||||||
|
pub loader: String,
|
||||||
|
pub loader_version: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct Mods {}
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
|
pub mod config;
|
||||||
pub mod fabric;
|
pub mod fabric;
|
||||||
pub mod vanilla;
|
pub mod vanilla;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue