remove unneccessary cmdargs feature
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
pub mod config;
|
||||
|
||||
#[cfg(feature = "cmdargs")]
|
||||
pub mod args;
|
||||
|
||||
+7
-15
@@ -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:#?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user