diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-23 00:38:34 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-23 00:38:34 +0200 |
commit | 500061375cae4700cb13a50705f627ba06835038 (patch) | |
tree | 24a38d4dc2ca3d7ac3fc576690812a035700f613 | |
parent | 1cf20810c5191c426f9226a13f4a0d0e09c8f74b (diff) | |
download | planetwars.dev-500061375cae4700cb13a50705f627ba06835038.tar.xz planetwars.dev-500061375cae4700cb13a50705f627ba06835038.zip |
support working_directory and command string
-rw-r--r-- | planetwars-client/Cargo.toml | 1 | ||||
-rw-r--r-- | planetwars-client/src/main.rs | 27 |
2 files changed, 25 insertions, 3 deletions
diff --git a/planetwars-client/Cargo.toml b/planetwars-client/Cargo.toml index 4ff96f2..c83950b 100644 --- a/planetwars-client/Cargo.toml +++ b/planetwars-client/Cargo.toml @@ -14,6 +14,7 @@ serde = { version = "1.0", features = ["derive"] } toml = "0.5" planetwars-matchrunner = { path = "../planetwars-matchrunner" } clap = { version = "3.2", features = ["derive", "env"]} +shlex = "1.1" [build-dependencies] tonic-build = "0.7.2" 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<String>, + command: Command, + working_directory: Option<String>, +} + +#[derive(Deserialize)] +#[serde(untagged)] +enum Command { + String(String), + Argv(Vec<String>), +} + +impl Command { + pub fn to_argv(&self) -> Vec<String> { + 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(); |