remove unneccessary cmdargs feature
All checks were successful
CI / Saltfish (push) Successful in -3m0s
CI / Saltfish [custom_pieces] (push) Successful in -3m1s

This commit is contained in:
fabolous005 2024-04-04 17:20:15 +02:00
parent d20a2d29fd
commit cc3da89aee
6 changed files with 34 additions and 45 deletions

View File

@ -25,28 +25,3 @@ jobs:
with: with:
command: build command: build
args: --release --no-default-features --features "custom_pieces" 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"

View File

@ -4,13 +4,11 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[features] [features]
default = ["cmdargs"]
custom_pieces = [] custom_pieces = []
cmdargs = ["dep:clap"]
[dependencies] [dependencies]
toml = { version = "0.8.12" } 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 = { version = "1.0.197", features = ["derive"] }
serde_derive = { version = "1.0.197" } serde_derive = { version = "1.0.197" }
num_cpus = "1.16.0" num_cpus = "1.16.0"

View File

@ -39,4 +39,17 @@ impl Args {
pub fn get_jobs(self) -> u8 { pub fn get_jobs(self) -> u8 {
self.jobs 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
}
} }

View File

@ -7,6 +7,8 @@ use crate::chess::piece::CustomPiece;
#[cfg(feature = "custom_pieces")] #[cfg(feature = "custom_pieces")]
use std::collections::HashMap; use std::collections::HashMap;
use crate::config::args::Args;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Engine { struct Engine {
@ -46,4 +48,15 @@ impl Config {
file.read_to_string(&mut config_string).expect("Failed to parse file to string"); file.read_to_string(&mut config_string).expect("Failed to parse file to string");
toml::from_str(&config_string).expect("Failed to parse toml") 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())
}),
}
}
} }

View File

@ -1,4 +1,2 @@
pub mod config; pub mod config;
#[cfg(feature = "cmdargs")]
pub mod args; pub mod args;

View File

@ -5,14 +5,10 @@
use config::config::Config; use config::config::Config;
#[cfg(feature = "cmdargs")]
use config::args::Args; use config::args::Args;
#[cfg(feature = "cmdargs")]
use clap::Parser; use clap::Parser;
// TODO: move all of this into seperate file
#[cfg(not(feature = "cmdargs"))]
use std::path::Path;
mod chess; mod chess;
mod config; mod config;
@ -21,17 +17,13 @@ mod config;
fn main() { fn main() {
let config; 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|{
// TODO: implement error handling and logging and handle this case appropriate println!("error parsing cmd args\n{:#?}", err);
let args = Args::try_parse().unwrap_or_else(|err|{println!("error parsing cmd args\n{:#?}", err); Args::default()}); Args::default()
config = Config::read(&args.get_config_path()); });
} config = Config::read(&args.get_config_path());
#[cfg(not(feature = "cmdargs"))]
{
config = Config::read(Path::new("./config.toml"));
}
println!("{config:#?}"); println!("{config:#?}");
} }