diff --git a/babylonia-terminal-cli/src/arguments.rs b/babylonia-terminal-cli/src/arguments.rs index c79b832..03fca73 100644 --- a/babylonia-terminal-cli/src/arguments.rs +++ b/babylonia-terminal-cli/src/arguments.rs @@ -3,16 +3,14 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Args { - /// Pass launch options to tinker the behavior of the game, this parameter have priotiy over the - /// --set-options param + #[command(subcommand)] + pub command: Option, + + /// Pass launch options to tinker the behavior of the game, this parameter have priority over the + /// set-launch-options command #[arg(long)] pub options: Option, - /// Set to the config launch options to tinker the behavior of the game, you need to run this - /// command one time to set your launch options to the configuration - #[arg(long)] - pub set_options: Option, - /// Show the logs direcly to the stdout of your terminal #[arg(long, default_value = "false")] pub logs: bool, diff --git a/babylonia-terminal-cli/src/commands.rs b/babylonia-terminal-cli/src/commands.rs new file mode 100644 index 0000000..55a4fb2 --- /dev/null +++ b/babylonia-terminal-cli/src/commands.rs @@ -0,0 +1,11 @@ +use clap::Subcommand; + +#[derive(Debug, Subcommand)] +pub enum Commands { + /// Set to the config launch options to tinker the behavior of the game, you need to run this + /// command one time to set your launch options to the configuration + SetLaunchOptions { launch_options: String }, + + /// Set the current game directory, this command will move all the current game file to the new one! + SetGamePath { new_game_directory: String }, +} diff --git a/babylonia-terminal-cli/src/main.rs b/babylonia-terminal-cli/src/main.rs index 0900c62..1c36f93 100644 --- a/babylonia-terminal-cli/src/main.rs +++ b/babylonia-terminal-cli/src/main.rs @@ -1,14 +1,17 @@ use babylonia_terminal_sdk::game_config::GameConfig; +use babylonia_terminal_sdk::utils; use clap::Parser; -use log::{debug, LevelFilter}; +use log::{debug, info, LevelFilter}; use simple_logger::SimpleLogger; mod arguments; +mod commands; pub mod game; pub mod reporter; pub mod utils; use crate::arguments::Args; +use crate::commands::Commands; #[tokio::main] async fn main() { @@ -29,11 +32,19 @@ async fn main() { let args = Args::parse(); debug!("Launch option -> {:?}", args.options); - if let Some(command) = args.set_options { - GameConfig::set_launch_options(Some(command)) - .await - .expect("Failed to save launch options into the config file"); + match args.command { + Some(Commands::SetLaunchOptions { launch_options }) => { + GameConfig::set_launch_options(Some(launch_options)) + .await + .expect("Failed to save launch options into the config file"); + info!("Successfully updated launch options!"); + } + Some(Commands::SetGamePath { new_game_directory }) => { + utils::fs::move_all_file_in_dir( + "~/.babylonia-terminal/PGR", + "~/.babylonia-terminal/PGR", + ); + } + None => game::run(args.options, args.logs).await, } - - game::run(args.options, args.logs).await; } diff --git a/babylonia-terminal-sdk/src/utils/fs.rs b/babylonia-terminal-sdk/src/utils/fs.rs new file mode 100644 index 0000000..3ecd8a1 --- /dev/null +++ b/babylonia-terminal-sdk/src/utils/fs.rs @@ -0,0 +1,36 @@ +use std::{ + path::PathBuf, + task::{Context, Poll}, +}; + +use log::debug; +use tokio::fs; + +pub async fn move_all_file_in_dir(dir: &PathBuf, new_dir: &PathBuf) -> Result<(), String> { + if !dir.is_dir() { + return Err(format!( + "{} is not a directory", + dir.as_os_str().to_str().unwrap() + )); + } + + if !dir.exists() { + return Err(format!( + "{} does not exist", + dir.as_os_str().to_str().unwrap() + )); + } + + if let Ok(mut objects) = fs::read_dir(dir).await { + while let Ok(Some(entry)) = objects.next_entry().await { + debug!("{:?}", entry); + } + } else { + return Err(format!( + "Failed to read directory -> {}", + dir.as_os_str().to_str().unwrap() + )); + } + + Ok(()) +} diff --git a/babylonia-terminal-sdk/src/utils/mod.rs b/babylonia-terminal-sdk/src/utils/mod.rs index 3d41723..35892d3 100644 --- a/babylonia-terminal-sdk/src/utils/mod.rs +++ b/babylonia-terminal-sdk/src/utils/mod.rs @@ -1,3 +1,4 @@ +pub mod fs; pub mod github_requester; pub mod kuro_prod_api;