refactor: extract cli and config into separate modules

This commit is contained in:
objz committed 2025-06-14 17:32:18 +02:00
1 parent 03c87a8df0
commit 159b21d39a
17 files changed
+479 -2436

No files matched your search

+129
View File
@@ -0,0 +1,129 @@
use crate::tui;
use clap::{Arg, ArgAction, Command};
pub fn init() {
let matches = Command::new("mcl")
.about("Minecraft CLI Launcher")
.version("1.0.0")
.subcommand_required(false)
.arg_required_else_help(false)
.subcommand(
Command::new("launch")
.about("Launch Minecraft with a specific profile")
.arg_required_else_help(true)
.arg(
Arg::new("profile")
.short('p')
.long("profile")
.help("Profile to launch (e.g., main)")
.required(true)
.action(ArgAction::Set),
)
.arg(
Arg::new("offline")
.short('o')
.long("offline")
.help("Launch Minecraft in offline mode")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("memory")
.short('m')
.long("memory")
.help("Set memory allocation for Minecraft (e.g., 4G, 512M)")
.action(ArgAction::Set),
)
.arg(
Arg::new("resolution")
.short('r')
.long("resolution")
.help("Set screen resolution (e.g., 1920x1080)")
.action(ArgAction::Set),
)
.arg(
Arg::new("jvm-args")
.short('j')
.long("jvm-args")
.help("Custom JVM arguments for Minecraft (e.g., -Xmx4G)")
.action(ArgAction::Set)
.num_args(1..),
)
.arg(
Arg::new("no-window")
.short('n')
.long("no-window")
.help("Run Minecraft in headless mode (no graphical window)")
.action(ArgAction::SetTrue),
),
)
.subcommand(
Command::new("profiles")
.about("Manage Minecraft profiles")
.arg_required_else_help(true)
.arg(
Arg::new("list")
.short('l')
.long("list")
.help("List all available profiles")
.conflicts_with("delete")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("delete")
.short('d')
.long("delete")
.help("Delete a specific profile")
.action(ArgAction::Set),
),
)
.get_matches();
if matches.subcommand().is_none() {
tui::show().unwrap()
}
match matches.subcommand() {
Some(("launch", launch_matches)) => {
let profile = launch_matches
.get_one::<String>("profile")
.expect("Profile is required");
let mem_default = String::from("Default");
let memory = launch_matches
.get_one::<String>("memory")
.unwrap_or(&mem_default);
let res_default = String::from("Default");
let resolution = launch_matches
.get_one::<String>("resolution")
.unwrap_or(&res_default);
let jvm_args = launch_matches
.get_many::<String>("jvm-args")
.map(|args| args.map(|s| s.as_str()).collect::<Vec<_>>().join(" "))
.unwrap_or_else(|| "None".to_string());
if launch_matches.get_flag("offline") {
tracing::debug!("Launching profile '{}' in offline mode...", profile);
} else {
tracing::debug!("Launching profile '{}' in online mode...", profile);
}
tracing::debug!("Memory: {}", memory);
tracing::debug!("Resolution: {}", resolution);
tracing::debug!("JVM Args: {}", jvm_args);
if launch_matches.get_flag("no-window") {
tracing::debug!("Running in headless mode...");
}
}
Some(("profiles", profiles_matches)) => {
if profiles_matches.get_flag("list") {
tracing::debug!("Listing all profiles...");
} else if let Some(profile) = profiles_matches.get_one::<String>("delete") {
tracing::debug!("Deleting profile '{}'...", profile);
}
}
_ => {}
}
}