From 4abc588ba091c41eace884d2fb4326a051e76a43 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Wed, 20 Oct 2021 12:58:03 +0200 Subject: [PATCH] Added tools, cleaned up main --- .vscode/launch.json | 45 +++++++++++++++++++ Cargo.lock | 106 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- src/main.rs | 92 +++++++++++++++++--------------------- 4 files changed, 194 insertions(+), 52 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e46e155 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,45 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'khetamine'", + "cargo": { + "args": [ + "build", + "--bin=khetamine", + "--package=khetamine" + ], + "filter": { + "name": "khetamine", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'khetamine'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=khetamine", + "--package=khetamine" + ], + "filter": { + "name": "khetamine", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 21b1d99..402b1bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,56 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "itoa" version = "0.4.8" @@ -12,10 +62,17 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" name = "khetamine" version = "0.1.0" dependencies = [ + "clap", "serde", "serde_json", ] +[[package]] +name = "libc" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2f96d100e1cf1929e7719b7edb3b90ab5298072638fccd77be9ce942ecdfce" + [[package]] name = "proc-macro2" version = "1.0.30" @@ -71,6 +128,12 @@ dependencies = [ "serde", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "syn" version = "1.0.80" @@ -82,8 +145,51 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 54803b6..5338869 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ edition = "2018" [dependencies] serde = { version = "1.0.130", features = ["derive"] } -serde_json = "1.0.68" \ No newline at end of file +serde_json = "1.0.68" +clap = "2.33.3" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4b5bb1f..40787ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,43 +1,35 @@ -use std::env; - -// mod models { -// pub mod board; -// pub mod piece; -// pub mod networking; -// } - -fn print_help() { - println!("Ey fam, hmu with dat '--serve' or '--join
'") -} - -fn start_game() { - println!("OK"); +mod models { + pub mod board; + pub mod piece; + pub mod networking; } +use clap::{Arg, App, SubCommand}; fn main() { - let args: Vec = env::args().collect(); - if (args.len() == 2) && ((args[1] == "--serve") | (args[1] == "serve")) { + let matches = App::new("Khetamine") + .version("1.0") + .author("oysteikt, felixalb") + .about("Play Khet with your friends!") + .arg(Arg::with_name("serve") + .short("s") + .long("serve") + .help("Run as game server, your friend connects as client.")) + .arg(Arg::with_name("connect") + .short("c") + .help("Connect to a server") + .value_name("ADRESS") + .takes_value(true) + .arg(Arg::with_name("v") + .short("v") + .multiple(true) + .help("Sets the level of verbosity")) + .subcommand(SubCommand::with_name("test") + .about("Runs various tests") + .version("1.3") + .author("felixalb")) + .get_matches(); - //Start game server - println!("Serving!"); - start_game(); - - } else if (args.len() == 3) && ((args[1] == "--join") | (args[1] == "join")) { - - //Join game server - println!("Joining!"); - start_game(); - - } else if (args.len() == 2) && (args[1] == "--help") { - - print_help(); - - } else { - - println!("What do you mean with {:?}\n", args); - print_help(); - - } + println!("{}", matches); // println!("{}", &serialize_move(models::networking::Action::Rotate { // from: (2, 2), @@ -47,18 +39,16 @@ fn main() { } - - -// fn serialize_move(action: models::networking::Action) -> str { -// let serialized = serde_json::to_string(&action); -// match serialized { -// Ok(s) => { -// println!("OK: {}", s); -// return &s; -// }, -// Err(_e) => { -// println!("Couldn't serialize..."); -// return (""); -// } -// } -// } \ No newline at end of file +fn serialize_move(action: models::networking::Action) -> String { + let serialized = serde_json::to_string(&action); + match serialized { + Ok(s) => { + // println!("{}", s); + return s; + }, + Err(_e) => { + println!("Couldn't serialize..."); + return String::from(""); + } + } + }