feat(cli): implement clap argument parsing and subcommands
This commit is contained in:
parent
5e45657cd9
commit
c922851f91
3 changed files with 84 additions and 2 deletions
33
crates/molotov-cli/src/commands.rs
Normal file
33
crates/molotov-cli/src/commands.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "molotov", author, version, about = "Native Roblox Runtime for Linux", long_about = None)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum Commands {
|
||||
/// Launch Roblox with the active profile
|
||||
Launch {
|
||||
#[arg(short, long)]
|
||||
place_id: Option<u64>,
|
||||
#[arg(long)]
|
||||
safe_mode: bool,
|
||||
},
|
||||
/// Check for and download the latest Roblox version
|
||||
Update,
|
||||
/// Apply or inspect FastFlag settings
|
||||
Fflags {
|
||||
#[arg(short, long)]
|
||||
profile: Option<String>,
|
||||
#[arg(short, long)]
|
||||
list: bool,
|
||||
},
|
||||
/// Clean old versions and cached files
|
||||
Clean,
|
||||
/// Show system diagnostics and status
|
||||
Diagnostics,
|
||||
}
|
||||
|
|
@ -1,4 +1,38 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
pub fn run(_args: &[String]) {
|
||||
println!("Molotov CLI placeholder");
|
||||
pub mod commands;
|
||||
use clap::Parser;
|
||||
use commands::{Cli, Commands};
|
||||
|
||||
pub fn run(args: &[String]) {
|
||||
let mut full_args = vec!["molotov".to_string()];
|
||||
full_args.extend_from_slice(args);
|
||||
|
||||
let cli = match Cli::try_parse_from(full_args) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
e.print().ok();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match cli.command {
|
||||
Some(Commands::Launch { place_id, safe_mode }) => {
|
||||
println!("🚀 Launching Molotov (Place: {:?}, Safe Mode: {})", place_id, safe_mode);
|
||||
}
|
||||
Some(Commands::Update) => {
|
||||
println!("🔄 Checking for Roblox updates...");
|
||||
}
|
||||
Some(Commands::Fflags { profile, list }) => {
|
||||
println!("⚙️ FastFlag manager (Profile: {:?}, List: {})", profile, list);
|
||||
}
|
||||
Some(Commands::Clean) => {
|
||||
println!("🧹 Cleaning old versions and temporary cache...");
|
||||
}
|
||||
Some(Commands::Diagnostics) => {
|
||||
println!("🩺 Running Molotov system diagnostics...");
|
||||
}
|
||||
None => {
|
||||
println!("No subcommand specified. Running in GUI mode.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
crates/molotov-cli/tests/cli_test.rs
Normal file
15
crates/molotov-cli/tests/cli_test.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use clap::Parser;
|
||||
use molotov_cli::commands::Cli;
|
||||
|
||||
#[test]
|
||||
fn test_cli_parse_launch_place() {
|
||||
let parsed = Cli::try_parse_from(["molotov", "launch", "--place-id", "1818"]);
|
||||
assert!(parsed.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cli_parse_clean_command() {
|
||||
let parsed = Cli::try_parse_from(["molotov", "clean"]);
|
||||
assert!(parsed.is_ok());
|
||||
}
|
||||
Reference in a new issue