From 500061375cae4700cb13a50705f627ba06835038 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 23 Jul 2022 00:38:34 +0200 Subject: support working_directory and command string --- planetwars-client/src/main.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'planetwars-client/src/main.rs') diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs index c9d97b0..6edcc2e 100644 --- a/planetwars-client/src/main.rs +++ b/planetwars-client/src/main.rs @@ -32,7 +32,24 @@ struct PlayMatch { struct BotConfig { #[allow(dead_code)] name: String, - command: Vec, + command: Command, + working_directory: Option, +} + +#[derive(Deserialize)] +#[serde(untagged)] +enum Command { + String(String), + Argv(Vec), +} + +impl Command { + pub fn to_argv(&self) -> Vec { + match self { + Command::Argv(vec) => vec.clone(), + Command::String(s) => shlex::split(s).expect("invalid command string"), + } + } } #[tokio::main] @@ -76,8 +93,12 @@ async fn run_player(bot_config: BotConfig, player_key: String, channel: Channel) }); let mut bot_process = Bot { - working_dir: PathBuf::from("."), - argv: bot_config.command, + working_dir: PathBuf::from( + bot_config + .working_directory + .unwrap_or_else(|| ".".to_string()), + ), + argv: bot_config.command.to_argv(), } .spawn_process(); -- cgit v1.2.3