This commit is contained in:
ALEZ-DEV 2024-11-06 18:29:56 +01:00
parent fb4e47eac7
commit 5da5987b6c
5 changed files with 71 additions and 14 deletions

View File

@ -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<crate::commands::Commands>,
/// 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<String>,
/// 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<String>,
/// Show the logs direcly to the stdout of your terminal
#[arg(long, default_value = "false")]
pub logs: bool,

View File

@ -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 },
}

View File

@ -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;
}

View File

@ -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(())
}

View File

@ -1,3 +1,4 @@
pub mod fs;
pub mod github_requester;
pub mod kuro_prod_api;