mcsm/src/main.rs

74 lines
2.3 KiB
Rust
Raw Normal View History

2026-08-30 16:38:53 +05:00
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(())
}