mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-15 00:48:52 +00:00
WIP
This commit is contained in:
parent
fb4e47eac7
commit
5da5987b6c
@ -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,
|
||||
|
||||
11
babylonia-terminal-cli/src/commands.rs
Normal file
11
babylonia-terminal-cli/src/commands.rs
Normal 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 },
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
36
babylonia-terminal-sdk/src/utils/fs.rs
Normal file
36
babylonia-terminal-sdk/src/utils/fs.rs
Normal 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(())
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
pub mod fs;
|
||||
pub mod github_requester;
|
||||
pub mod kuro_prod_api;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user