aboutsummaryrefslogtreecommitdiff
path: root/planetwars-cli/src/workspace/bot.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2021-12-28 14:57:41 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2021-12-28 14:57:41 +0100
commitdacc05a41b77bf2e86e27ac354db9b047c661a7d (patch)
tree3d71fa60ff3449f73ec8bb6066ae82733eb46ee4 /planetwars-cli/src/workspace/bot.rs
parent5ca8dd4c842ee681ce81a6a7bbd5005cd5b98d3c (diff)
downloadplanetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.tar.xz
planetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.zip
refactor workspace code
Diffstat (limited to 'planetwars-cli/src/workspace/bot.rs')
-rw-r--r--planetwars-cli/src/workspace/bot.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/planetwars-cli/src/workspace/bot.rs b/planetwars-cli/src/workspace/bot.rs
new file mode 100644
index 0000000..3cd4f87
--- /dev/null
+++ b/planetwars-cli/src/workspace/bot.rs
@@ -0,0 +1,40 @@
+use shlex;
+use std::fs;
+use std::io;
+use std::path::{Path, PathBuf};
+
+use serde::{Deserialize, Serialize};
+
+const BOT_CONFIG_FILENAME: &str = "botconfig.toml";
+
+pub struct WorkspaceBot {
+ pub path: PathBuf,
+ pub config: BotConfig,
+}
+
+impl WorkspaceBot {
+ pub fn open(path: &Path) -> io::Result<Self> {
+ let config_path = path.join(BOT_CONFIG_FILENAME);
+ let config_str = fs::read_to_string(config_path)?;
+ let bot_config: BotConfig = toml::from_str(&config_str)?;
+
+ Ok(WorkspaceBot {
+ path: path.to_path_buf(),
+ config: bot_config,
+ })
+ }
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct BotConfig {
+ pub name: String,
+ pub run_command: String,
+}
+
+impl BotConfig {
+ pub fn get_run_argv(&self) -> Vec<String> {
+ // TODO: proper error handling
+ shlex::split(&self.run_command)
+ .expect("Failed to parse bot run command. Check for unterminated quotes.")
+ }
+}