From cc3da89aee5e0b975b6ce92df3c83bdf67222e04 Mon Sep 17 00:00:00 2001 From: fabolous005 Date: Thu, 4 Apr 2024 17:20:15 +0200 Subject: [PATCH] remove unneccessary cmdargs feature --- .gitea/workflows/build.yaml | 25 ------------------------- Cargo.toml | 4 +--- src/config/args.rs | 13 +++++++++++++ src/config/config.rs | 13 +++++++++++++ src/config/mod.rs | 2 -- src/main.rs | 22 +++++++--------------- 6 files changed, 34 insertions(+), 45 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index c4d9adb..053a206 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -25,28 +25,3 @@ jobs: with: command: build args: --release --no-default-features --features "custom_pieces" - build_cmdargs: - name: Saltfish [cmdargs] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --no-default-features --features "cmdargs" - build_cmdargs_custom_pieces: - name: Saltfish [cmdargs custom_pieces] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: actions-rs/cargo@v1 - with: - command: build - args: > - --release --no-default-features --features "cmdargs custom_pieces" diff --git a/Cargo.toml b/Cargo.toml index 723af39..a1e9abd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,11 @@ version = "0.1.0" edition = "2021" [features] -default = ["cmdargs"] custom_pieces = [] -cmdargs = ["dep:clap"] [dependencies] toml = { version = "0.8.12" } -clap = { version = "4.5.4", features = ["derive"], optional = true } +clap = { version = "4.5.4", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] } serde_derive = { version = "1.0.197" } num_cpus = "1.16.0" diff --git a/src/config/args.rs b/src/config/args.rs index 5076b12..7dc8116 100644 --- a/src/config/args.rs +++ b/src/config/args.rs @@ -39,4 +39,17 @@ impl Args { pub fn get_jobs(self) -> u8 { self.jobs } + + pub fn get_ref_depth(&self) -> u8 { + self.depth + } + + pub fn get_ref_strenght(&self) -> u8 { + self.strenght + } + + pub fn get_ref_jobs(&self) -> u8 { + self.jobs + } + } diff --git a/src/config/config.rs b/src/config/config.rs index b39711a..2d8e1bf 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -7,6 +7,8 @@ use crate::chess::piece::CustomPiece; #[cfg(feature = "custom_pieces")] use std::collections::HashMap; +use crate::config::args::Args; + #[derive(Debug, Deserialize)] struct Engine { @@ -46,4 +48,15 @@ impl Config { file.read_to_string(&mut config_string).expect("Failed to parse file to string"); toml::from_str(&config_string).expect("Failed to parse toml") } + + pub fn merge_args(self, args: &Args) -> Self { + Self { + #[cfg(feature = "custom_pieces")] + pieces: self.pieces, + engine: Some(Engine { + depth: Some(args.get_ref_depth()), + jobs: Some(args.get_ref_jobs()) + }), + } + } } diff --git a/src/config/mod.rs b/src/config/mod.rs index a681f01..1c94de5 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,4 +1,2 @@ pub mod config; - -#[cfg(feature = "cmdargs")] pub mod args; diff --git a/src/main.rs b/src/main.rs index ee270f9..abf48a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,14 +5,10 @@ use config::config::Config; - -#[cfg(feature = "cmdargs")] use config::args::Args; -#[cfg(feature = "cmdargs")] use clap::Parser; +// TODO: move all of this into seperate file -#[cfg(not(feature = "cmdargs"))] -use std::path::Path; mod chess; mod config; @@ -21,17 +17,13 @@ mod config; fn main() { let config; - #[cfg(feature = "cmdargs")] - { - // TODO: implement error handling and logging and handle this case appropriate - let args = Args::try_parse().unwrap_or_else(|err|{println!("error parsing cmd args\n{:#?}", err); Args::default()}); - config = Config::read(&args.get_config_path()); - } + // TODO: implement error handling and logging and handle this case appropriate + let args = Args::try_parse().unwrap_or_else(|err|{ + println!("error parsing cmd args\n{:#?}", err); + Args::default() + }); + config = Config::read(&args.get_config_path()); - #[cfg(not(feature = "cmdargs"))] - { - config = Config::read(Path::new("./config.toml")); - } println!("{config:#?}"); }