From dd4f0838ab6d591152b24901c1a02e748052bc04 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 23 Sep 2023 03:01:36 -0400 Subject: [PATCH] Move CLI crate to root of workspace Somehow I missed that this was a thing you could do? It's a much cleaner organization, and it makes it so that you don't have to explicitly specify the crate to build. --- Cargo.lock | 26 +++++++------- Cargo.toml | 29 ++++++++++++--- cli/build.rs => build.rs | 2 +- cli/Cargo.toml | 24 ------------- cli/src/main.rs | 39 --------------------- flake.nix | 1 - schema/build.rs | 2 +- schema/{src => }/startgg.graphql | 0 {cli/src => src}/datasets.rs | 0 src/main.rs | 35 ++++++++++++++++++ {cli/src => src}/queries.rs | 0 {cli/src => src}/queries/player_info.rs | 0 {cli/src => src}/queries/search_games.rs | 0 {cli/src => src}/queries/tournament_sets.rs | 0 14 files changed, 75 insertions(+), 83 deletions(-) rename cli/build.rs => build.rs (68%) delete mode 100644 cli/Cargo.toml delete mode 100644 cli/src/main.rs rename schema/{src => }/startgg.graphql (100%) rename {cli/src => src}/datasets.rs (100%) create mode 100644 src/main.rs rename {cli/src => src}/queries.rs (100%) rename {cli/src => src}/queries/player_info.rs (100%) rename {cli/src => src}/queries/search_games.rs (100%) rename {cli/src => src}/queries/tournament_sets.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 63f0ce0..21fc571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,19 +107,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "cli" -version = "0.1.0" -dependencies = [ - "cynic", - "cynic-codegen", - "dirs", - "reqwest", - "schema", - "serde", - "sqlite", -] - [[package]] name = "combine" version = "3.8.1" @@ -389,6 +376,19 @@ dependencies = [ "wasi", ] +[[package]] +name = "ggelo" +version = "0.1.0" +dependencies = [ + "cynic", + "cynic-codegen", + "dirs", + "reqwest", + "schema", + "serde", + "sqlite", +] + [[package]] name = "gimli" version = "0.28.0" diff --git a/Cargo.toml b/Cargo.toml index 90641bc..d7d0146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,26 @@ [workspace] -members = [ - "schema", - "cli" -] + +[package] +name = "ggelo" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "ggelo" +path = "src/main.rs" + +[dependencies] +# GraphQL schema +schema.path = "schema" + +# API access +cynic = { version = "3.2", features = ["http-reqwest-blocking"] } +reqwest = "0.11" +serde = "1.0" + +# Local file manipulation +dirs = "5.0" +sqlite = "0.31" + +[build-dependencies] +cynic-codegen = "3.2" diff --git a/cli/build.rs b/build.rs similarity index 68% rename from cli/build.rs rename to build.rs index cce8286..df06903 100644 --- a/cli/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ fn main() { cynic_codegen::register_schema("startgg") - .from_sdl_file("../schema/src/startgg.graphql") + .from_sdl_file("schema/startgg.graphql") .unwrap() .as_default() .unwrap(); diff --git a/cli/Cargo.toml b/cli/Cargo.toml deleted file mode 100644 index a094423..0000000 --- a/cli/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "cli" -version = "0.1.0" -edition = "2021" - -[[bin]] -name = "ggelo" -path = "src/main.rs" - -[dependencies] -# GraphQL schema -schema.path = "../schema" - -# API access -cynic = { version = "3.2", features = ["http-reqwest-blocking"] } -reqwest = "0.11" -serde = "1.0" - -# Local file manipulation -dirs = "5.0" -sqlite = "0.31" - -[build-dependencies] -cynic-codegen = "3.2" diff --git a/cli/src/main.rs b/cli/src/main.rs deleted file mode 100644 index 8dedce1..0000000 --- a/cli/src/main.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![feature(iterator_try_collect)] - -mod queries; -use queries::*; - -mod datasets; - -fn main() { - let mut config_dir = dirs::config_dir().unwrap(); - config_dir.push("ggelo"); - let auth_key = get_auth_key(&config_dir).expect("Could not find authorization key"); - - if let Some(response) = run_query::( - TournamentSetsVars { - last_query: Timestamp(1), - game_id: VideogameId(1386), - country: None, - state: Some("GA"), - }, - &auth_key, - ) { - println!("Succeeded"); - for tournament in response { - println!("Tournament: {}", tournament.name); - for set in tournament.sets { - println!( - "Winner: {}", - if set.winner { - set.player2.0 - } else { - set.player1.0 - } - ); - } - } - } else { - println!("Invalid GraphQL response"); - } -} diff --git a/flake.nix b/flake.nix index 29d8a19..10ad12c 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,6 @@ pname = "ggelo"; version = "0.1.0"; src = craneLib.path ./.; - cargoBuildFlags = "-p cli"; buildInputs = [ pkgs.openssl pkgs.sqlite ]; nativeBuildInputs = [ pkgs.pkg-config ]; }; diff --git a/schema/build.rs b/schema/build.rs index 6f1123f..190cea4 100644 --- a/schema/build.rs +++ b/schema/build.rs @@ -1,6 +1,6 @@ fn main() { cynic_codegen::register_schema("startgg") - .from_sdl_file("src/startgg.graphql") + .from_sdl_file("startgg.graphql") .unwrap() .as_default() .unwrap(); diff --git a/schema/src/startgg.graphql b/schema/startgg.graphql similarity index 100% rename from schema/src/startgg.graphql rename to schema/startgg.graphql diff --git a/cli/src/datasets.rs b/src/datasets.rs similarity index 100% rename from cli/src/datasets.rs rename to src/datasets.rs diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5051c18 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,35 @@ +#![feature(iterator_try_collect)] + +use std::io::{self, Write}; + +mod queries; +use queries::*; +mod datasets; +use datasets::*; + +fn main() { + let mut config_dir = dirs::config_dir().unwrap(); + config_dir.push("ggelo"); + + let path = dataset_path(&config_dir, "test"); + 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, + }; + + update_from_set(&connection, set_data.clone()).unwrap(); + println!("{:?}", get_ratings(&connection, &set_data.teams).unwrap()); +} diff --git a/cli/src/queries.rs b/src/queries.rs similarity index 100% rename from cli/src/queries.rs rename to src/queries.rs diff --git a/cli/src/queries/player_info.rs b/src/queries/player_info.rs similarity index 100% rename from cli/src/queries/player_info.rs rename to src/queries/player_info.rs diff --git a/cli/src/queries/search_games.rs b/src/queries/search_games.rs similarity index 100% rename from cli/src/queries/search_games.rs rename to src/queries/search_games.rs diff --git a/cli/src/queries/tournament_sets.rs b/src/queries/tournament_sets.rs similarity index 100% rename from cli/src/queries/tournament_sets.rs rename to src/queries/tournament_sets.rs