From 3130d82e95fbb0194d3890ef9845c72c091e45d9 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 26 Sep 2023 22:36:03 -0400 Subject: [PATCH] Implement beginnings of CLI --- Cargo.lock | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++ src/main.rs | 82 ++++++++++++++++++++++++++++++---------- 3 files changed, 173 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21fc571..509d1c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,6 +29,54 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "ascii" version = "0.9.3" @@ -107,6 +155,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824956d0dca8334758a5b7f7e50518d66ea319330cbceedcf76905c2f6ab30e3" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122ec64120a49b4563ccaedcbea7818d069ed8e9aa6d829b82d8a4128936b2ab" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.29", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "combine" version = "3.8.1" @@ -380,6 +474,7 @@ dependencies = [ name = "ggelo" version = "0.1.0" dependencies = [ + "clap", "cynic", "cynic-codegen", "dirs", @@ -430,6 +525,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.2" @@ -1249,6 +1350,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index d7d0146..fe26228 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,9 @@ name = "ggelo" path = "src/main.rs" [dependencies] +# CLI +clap = { version = "4.4", features = ["derive"] } + # GraphQL schema schema.path = "schema" diff --git a/src/main.rs b/src/main.rs index be48a8b..1244d7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![feature(iterator_try_collect)] +use clap::{Parser, Subcommand}; use std::io::{self, Write}; mod queries; @@ -9,36 +10,79 @@ use state::*; mod datasets; use datasets::*; +/// ## CLI Structs + +#[derive(Parser)] +#[command(name = "StartGGElo")] +#[command(author = "Kiana Sheibani ")] +#[command(version = "0.1.0")] +#[command(about = "Elo rating calculator for start.gg tournaments", long_about = None)] +#[command(propagate_version = true)] +struct Cli { + #[command(subcommand)] + subcommand: Subcommands, + #[arg(long)] + auth_token: Option, +} + +#[derive(Subcommand)] +enum Subcommands { + Dataset { + #[command(subcommand)] + subcommand: DatasetSC, + }, +} + +#[derive(Subcommand)] +enum DatasetSC { + List, +} + fn main() { + let cli = Cli::parse(); + let mut config_dir = dirs::config_dir().unwrap(); config_dir.push("ggelo"); let auth_token = get_auth_key(&config_dir).unwrap(); + let app_state = AppState { + config_dir, + auth_token, + }; + + match cli.subcommand { + Subcommands::Dataset { + subcommand: DatasetSC::List, + } => dataset_list(app_state), + } + // let config = AppState { // config_dir, // auth_token, // }; - let path = dataset_path(&config_dir, "test").unwrap(); - let connection = open_dataset(&path).unwrap(); + // let path = dataset_path(&config_dir, "test").unwrap(); + // let connection = open_dataset(&path).unwrap(); - let set_data = SetData { - teams: vec![ - vec![PlayerData { - id: PlayerId(1), - name: Some("player1".to_owned()), - prefix: None, - }], - vec![PlayerData { - id: PlayerId(2), - name: Some("player2".to_owned()), - prefix: None, - }], - ], - winner: 0, - }; + // let set_data = SetData { + // teams: vec![ + // vec![PlayerData { + // id: PlayerId(1), + // name: Some("player1".to_owned()), + // prefix: None, + // }], + // vec![PlayerData { + // id: PlayerId(2), + // name: Some("player2".to_owned()), + // prefix: None, + // }], + // ], + // winner: 0, + // }; - update_from_set(&connection, set_data.clone()).unwrap(); - println!("{:?}", get_ratings(&connection, &set_data.teams).unwrap()); + // update_from_set(&connection, set_data.clone()).unwrap(); + // println!("{:?}", get_ratings(&connection, &set_data.teams).unwrap()); } + +fn dataset_list(state: AppState) {}