2024-08-13 23:56:57 +01:00
|
|
|
mod modpack;
|
|
|
|
|
|
|
|
use clap::{Parser, Subcommand};
|
2024-08-14 20:51:42 +01:00
|
|
|
use modpack::{ModLoader, ModMeta, ModProvider, ModpackMeta};
|
|
|
|
use std::{error::Error, path::PathBuf};
|
2024-08-13 23:56:57 +01:00
|
|
|
|
|
|
|
/// A Minecraft Modpack Manager
|
|
|
|
#[derive(Parser)]
|
|
|
|
#[command(version, about, long_about = None)]
|
|
|
|
struct Cli {
|
|
|
|
#[command(subcommand)]
|
|
|
|
command: Option<Commands>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
enum Commands {
|
2024-08-14 22:32:45 +01:00
|
|
|
/// Initialise a new mcmpmgr project in the specified directory (or current dir if not specified)
|
2024-08-13 23:56:57 +01:00
|
|
|
Init {
|
2024-08-14 21:28:40 +01:00
|
|
|
/// The root modpack project directory
|
2024-08-13 23:56:57 +01:00
|
|
|
directory: Option<PathBuf>,
|
2024-08-14 21:28:40 +01:00
|
|
|
/// Name of the modpack project
|
|
|
|
#[arg(long)]
|
|
|
|
name: Option<String>,
|
|
|
|
/// The modpack's Minecraft version
|
2024-08-13 23:56:57 +01:00
|
|
|
#[arg(long, default_value_t = String::from("1.20.1"))]
|
|
|
|
mc_version: String,
|
2024-08-14 21:28:40 +01:00
|
|
|
/// The modpack's modloader
|
|
|
|
#[arg(long, default_value_t = modpack::ModLoader::Fabric)]
|
|
|
|
modloader: modpack::ModLoader,
|
|
|
|
},
|
2024-08-14 22:32:45 +01:00
|
|
|
/// Create and initialise a new mcmpmgr project in the current directory
|
2024-08-14 21:28:40 +01:00
|
|
|
New {
|
|
|
|
/// Name of the new modpack project
|
|
|
|
name: String,
|
|
|
|
/// The modpack's Minecraft version
|
|
|
|
#[arg(long, default_value_t = String::from("1.20.1"))]
|
|
|
|
mc_version: String,
|
|
|
|
/// The modpack's modloader
|
2024-08-13 23:56:57 +01:00
|
|
|
#[arg(long, default_value_t = modpack::ModLoader::Fabric)]
|
|
|
|
modloader: modpack::ModLoader,
|
|
|
|
},
|
2024-08-14 22:32:45 +01:00
|
|
|
/// Add a new mod to the modpack
|
|
|
|
Add {
|
|
|
|
/// Name of the mod to add to the project, optionally including a version
|
|
|
|
name: String,
|
|
|
|
/// Providers to download the mods from
|
|
|
|
#[arg(long)]
|
|
|
|
providers: Vec<ModProvider>,
|
|
|
|
/// URL to download the mod from
|
|
|
|
#[arg(long)]
|
|
|
|
url: Option<String>
|
|
|
|
}
|
2024-08-13 23:56:57 +01:00
|
|
|
}
|
|
|
|
|
2024-08-14 20:51:42 +01:00
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
2024-08-13 23:56:57 +01:00
|
|
|
let cli = Cli::parse();
|
|
|
|
|
|
|
|
if let Some(command) = cli.command {
|
|
|
|
match command {
|
|
|
|
Commands::Init {
|
|
|
|
directory,
|
|
|
|
mc_version,
|
|
|
|
modloader,
|
2024-08-14 21:28:40 +01:00
|
|
|
name,
|
2024-08-13 23:56:57 +01:00
|
|
|
} => {
|
2024-08-14 20:51:42 +01:00
|
|
|
let dir = directory.unwrap_or(std::env::current_dir()?);
|
2024-08-14 21:28:40 +01:00
|
|
|
let pack_name = if let Some(name) = name {
|
|
|
|
name
|
|
|
|
} else {
|
|
|
|
dir.file_name()
|
|
|
|
.ok_or(format!(
|
|
|
|
"Cannot find pack name based on directory '{}'",
|
|
|
|
dir.display()
|
|
|
|
))?
|
|
|
|
.to_string_lossy()
|
|
|
|
.into()
|
|
|
|
};
|
|
|
|
println!(
|
|
|
|
"Initializing project '{}' at '{}'...",
|
|
|
|
&pack_name,
|
|
|
|
dir.display()
|
|
|
|
);
|
|
|
|
let mc_modpack_meta: ModpackMeta =
|
|
|
|
ModpackMeta::new(&pack_name, &mc_version, modloader);
|
|
|
|
mc_modpack_meta.init_project(&dir)?;
|
|
|
|
}
|
|
|
|
Commands::New {
|
|
|
|
name,
|
|
|
|
mc_version,
|
|
|
|
modloader,
|
|
|
|
} => {
|
|
|
|
let dir = std::env::current_dir()?.join(PathBuf::from(&name));
|
|
|
|
println!(
|
|
|
|
"Creating new modpack project '{}' at '{}'...",
|
|
|
|
&name,
|
|
|
|
dir.display()
|
|
|
|
);
|
|
|
|
std::fs::create_dir_all(&dir)?;
|
|
|
|
let mc_modpack_meta: ModpackMeta = ModpackMeta::new(&name, &mc_version, modloader);
|
|
|
|
mc_modpack_meta.init_project(&dir)?;
|
2024-08-13 23:56:57 +01:00
|
|
|
}
|
2024-08-14 22:32:45 +01:00
|
|
|
Commands::Add { name, providers, url } => {
|
|
|
|
let mut modpack_meta = ModpackMeta::load_from_current_directory()?;
|
|
|
|
|
|
|
|
let mut mod_meta = ModMeta::new(&name)?;
|
|
|
|
if let Some(url) = url {
|
|
|
|
mod_meta = mod_meta.url(&url);
|
|
|
|
}
|
|
|
|
for provider in providers.into_iter() {
|
|
|
|
mod_meta = mod_meta.provider(provider);
|
|
|
|
}
|
|
|
|
modpack_meta = modpack_meta.add_mod(mod_meta);
|
|
|
|
modpack_meta.save_current_dir_project()?;
|
|
|
|
},
|
2024-08-13 23:56:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|