initial commit

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ife1391ed23a1e7f388b1b5eca90b9ea76a6a6964
This commit is contained in:
raf 2026-01-29 19:36:25 +03:00
commit ef28bdaeb4
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
63 changed files with 17292 additions and 0 deletions

67
src/cli/commands/init.rs Normal file
View file

@ -0,0 +1,67 @@
use std::{collections::HashMap, path::Path};
use crate::{
cli::InitArgs,
error::PakkerError,
model::{Config, LockFile, Target},
};
pub async fn execute(
args: InitArgs,
lockfile_path: &Path,
config_path: &Path,
) -> Result<(), PakkerError> {
if lockfile_path.exists() {
return Err(PakkerError::AlreadyExists(
"Lock file already exists".into(),
));
}
let target = args.target.as_str();
let target_enum = match target {
"curseforge" => Target::CurseForge,
"modrinth" => Target::Modrinth,
"multiplatform" => Target::Multiplatform,
_ => {
return Err(PakkerError::InvalidInput(format!(
"Invalid target: {target}"
)));
},
};
let mc_versions = vec![args.mc_version];
let mut loaders = HashMap::new();
loaders.insert(args.loader, args.loader_version);
let lockfile = LockFile {
target: Some(target_enum),
mc_versions,
loaders,
projects: Vec::new(),
lockfile_version: 1,
};
// Save expects directory path, so get parent directory
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
lockfile.save(lockfile_dir)?;
let config = Config {
name: args.name.unwrap_or_else(|| "My Modpack".to_string()),
version: args.version.unwrap_or_else(|| "1.0.0".to_string()),
description: None,
author: None,
overrides: vec!["overrides".to_string()],
server_overrides: None,
client_overrides: None,
paths: HashMap::new(),
projects: None,
export_profiles: None,
};
let config_dir = config_path.parent().unwrap_or(Path::new("."));
config.save(config_dir)?;
println!("Initialized new modpack with target: {target}");
Ok(())
}