Implement beginnings of CLI

This commit is contained in:
Kiana Sheibani 2023-09-26 22:36:03 -04:00
parent c8cb974762
commit 3130d82e95
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 173 additions and 19 deletions

107
Cargo.lock generated
View file

@ -29,6 +29,54 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" 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]] [[package]]
name = "ascii" name = "ascii"
version = "0.9.3" version = "0.9.3"
@ -107,6 +155,52 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 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]] [[package]]
name = "combine" name = "combine"
version = "3.8.1" version = "3.8.1"
@ -380,6 +474,7 @@ dependencies = [
name = "ggelo" name = "ggelo"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap",
"cynic", "cynic",
"cynic-codegen", "cynic-codegen",
"dirs", "dirs",
@ -430,6 +525,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.2" version = "0.3.2"
@ -1249,6 +1350,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"

View file

@ -10,6 +10,9 @@ name = "ggelo"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
# CLI
clap = { version = "4.4", features = ["derive"] }
# GraphQL schema # GraphQL schema
schema.path = "schema" schema.path = "schema"

View file

@ -1,5 +1,6 @@
#![feature(iterator_try_collect)] #![feature(iterator_try_collect)]
use clap::{Parser, Subcommand};
use std::io::{self, Write}; use std::io::{self, Write};
mod queries; mod queries;
@ -9,36 +10,79 @@ use state::*;
mod datasets; mod datasets;
use datasets::*; use datasets::*;
/// ## CLI Structs
#[derive(Parser)]
#[command(name = "StartGGElo")]
#[command(author = "Kiana Sheibani <kiana.a.sheibani@gmail.com>")]
#[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<String>,
}
#[derive(Subcommand)]
enum Subcommands {
Dataset {
#[command(subcommand)]
subcommand: DatasetSC,
},
}
#[derive(Subcommand)]
enum DatasetSC {
List,
}
fn main() { fn main() {
let cli = Cli::parse();
let mut config_dir = dirs::config_dir().unwrap(); let mut config_dir = dirs::config_dir().unwrap();
config_dir.push("ggelo"); config_dir.push("ggelo");
let auth_token = get_auth_key(&config_dir).unwrap(); 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 { // let config = AppState {
// config_dir, // config_dir,
// auth_token, // auth_token,
// }; // };
let path = dataset_path(&config_dir, "test").unwrap(); // let path = dataset_path(&config_dir, "test").unwrap();
let connection = open_dataset(&path).unwrap(); // let connection = open_dataset(&path).unwrap();
let set_data = SetData { // let set_data = SetData {
teams: vec![ // teams: vec![
vec![PlayerData { // vec![PlayerData {
id: PlayerId(1), // id: PlayerId(1),
name: Some("player1".to_owned()), // name: Some("player1".to_owned()),
prefix: None, // prefix: None,
}], // }],
vec![PlayerData { // vec![PlayerData {
id: PlayerId(2), // id: PlayerId(2),
name: Some("player2".to_owned()), // name: Some("player2".to_owned()),
prefix: None, // prefix: None,
}], // }],
], // ],
winner: 0, // winner: 0,
}; // };
update_from_set(&connection, set_data.clone()).unwrap(); // update_from_set(&connection, set_data.clone()).unwrap();
println!("{:?}", get_ratings(&connection, &set_data.teams).unwrap()); // println!("{:?}", get_ratings(&connection, &set_data.teams).unwrap());
} }
fn dataset_list(state: AppState) {}