initlal project setup

This commit is contained in:
RafayAhmad7548 2026-08-30 16:38:53 +05:00
commit 505bfbbb5d
No known key found for this signature in database
6 changed files with 2146 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

2028
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

12
Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "mcsm"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.6.6", features = ["derive"] }
dialoguer = { version = "0.12.0", features = ["fuzzy-select"] }
reqwest = { version = "0.13.4", features = ["json"] }
serde = { version = "1.0.229", features = ["derive"] }
tokio = { version = "1.53.1", features = ["full"] }
toml = "1.1.4"

73
src/main.rs Normal file
View 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(())
}

1
src/models/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod vanilla;

31
src/models/vanilla.rs Normal file
View file

@ -0,0 +1,31 @@
use serde::Deserialize;
#[derive(Deserialize)]
pub struct VanillaVersions {
pub latest: VanillaLatestVersion,
pub versions: Vec<VanillaVersion>,
}
#[derive(Deserialize)]
pub struct VanillaLatestVersion {
pub release: String,
pub snapshot: String,
}
#[derive(Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum VanillaVersionType {
Snapshot,
Release,
OldBeta,
OldAlpha,
}
#[derive(Deserialize)]
pub struct VanillaVersion {
pub id: String,
#[serde(rename = "type")]
pub version_type: VanillaVersionType,
pub url: String,
}