initlal project setup
This commit is contained in:
commit
505bfbbb5d
6 changed files with 2146 additions and 0 deletions
73
src/main.rs
Normal file
73
src/main.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
mod models;
|
||||
|
||||
use std::{error::Error, fs};
|
||||
use clap::{Parser, Subcommand, builder::styling::{self}};
|
||||
use dialoguer::{FuzzySelect, Select, theme::ColorfulTheme};
|
||||
use crate::models::vanilla::{VanillaVersionType, VanillaVersions};
|
||||
|
||||
|
||||
fn styles() -> styling::Styles {
|
||||
styling::Styles::styled()
|
||||
.header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
|
||||
.usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
|
||||
.literal(styling::AnsiColor::Cyan.on_default() | styling::Effects::BOLD)
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "mcsm", version, about, styles = styles())]
|
||||
struct Mcsm {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Init {
|
||||
name: String
|
||||
}
|
||||
}
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mcsm = Mcsm::parse();
|
||||
|
||||
match mcsm.command {
|
||||
Commands::Init { name } => {
|
||||
fs::create_dir(name)?;
|
||||
|
||||
let loaders = vec!["Vanilla", "Fabric"];
|
||||
let loader_index = Select::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Select Loader")
|
||||
.items(&loaders)
|
||||
.default(0)
|
||||
.interact()?;
|
||||
|
||||
match loader_index {
|
||||
0 => {
|
||||
const URL: &str = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
|
||||
let res: VanillaVersions = reqwest::get(URL).await?.json().await?;
|
||||
let release_versions = res.versions
|
||||
.iter()
|
||||
.filter(|version| version.version_type == VanillaVersionType::Release)
|
||||
.map(|version| version.id.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let version_index = FuzzySelect::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Select Version")
|
||||
.items(&release_versions)
|
||||
.default(0)
|
||||
.interact()?;
|
||||
|
||||
println!("you selected {} with version {}", loaders[loader_index], release_versions[version_index]);
|
||||
|
||||
|
||||
},
|
||||
1 => {
|
||||
|
||||
}
|
||||
_ => return Err("Invalid selection".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue