aboutsummaryrefslogtreecommitdiff
path: root/planetwars-cli/src/commands/init.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2021-12-26 21:54:26 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2021-12-26 21:54:26 +0100
commit0d03a0fbc214dd3fb9a8af562f9d88cccaf5f2c0 (patch)
treeaa93706592a050fc01a220546b73889faeab80fe /planetwars-cli/src/commands/init.rs
parentc04d4a449bd147c632c0b6ceae04f0514803b66f (diff)
downloadplanetwars.dev-0d03a0fbc214dd3fb9a8af562f9d88cccaf5f2c0.tar.xz
planetwars.dev-0d03a0fbc214dd3fb9a8af562f9d88cccaf5f2c0.zip
refactor commands
Diffstat (limited to 'planetwars-cli/src/commands/init.rs')
-rw-r--r--planetwars-cli/src/commands/init.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/planetwars-cli/src/commands/init.rs b/planetwars-cli/src/commands/init.rs
new file mode 100644
index 0000000..42491bc
--- /dev/null
+++ b/planetwars-cli/src/commands/init.rs
@@ -0,0 +1,38 @@
+use std::path::PathBuf;
+
+use clap::Parser;
+use futures::io;
+
+#[derive(Parser)]
+pub struct InitCommand {
+ /// project root directory
+ path: String,
+}
+
+macro_rules! copy_asset {
+ ($path:expr, $file_name:literal) => {
+ ::std::fs::write(
+ $path.join($file_name),
+ include_bytes!(concat!("../../assets/", $file_name)),
+ )?;
+ };
+}
+
+impl InitCommand {
+ pub async fn run(self) -> io::Result<()> {
+ let path = PathBuf::from(&self.path);
+
+ // create directories
+ std::fs::create_dir_all(&path)?;
+ std::fs::create_dir(path.join("maps"))?;
+ std::fs::create_dir(path.join("matches"))?;
+ std::fs::create_dir_all(path.join("bots/simplebot"))?;
+
+ // create files
+ copy_asset!(path, "pw_project.toml");
+ copy_asset!(path.join("maps"), "hex.json");
+ copy_asset!(path.join("bots/simplebot"), "simplebot.py");
+
+ Ok(())
+ }
+}