feat: read command line arguments

This commit is contained in:
Alex Wellnitz 2024-02-19 12:51:41 +01:00
parent fc772f4b6a
commit bfa64ebeee
2 changed files with 8 additions and 4 deletions

View File

@ -5,13 +5,13 @@ use clap::Parser;
pub struct Args { pub struct Args {
/// Config file path /// Config file path
#[arg(short, long, default_value = "/etc/rustysearch/config.json")] #[arg(short, long, default_value = "/etc/rustysearch/config.json")]
config: String, pub config_path: String,
/// Change the log level /// Change the log level
#[arg(short = 'l', long, default_value = "info")] #[arg(short = 'l', long, default_value = "info")]
loglevel: String, pub log_level: String,
/// Change Database path /// Change Database path
#[arg(short = 'D', long, default_value = "/tmp/rustysearch.db")] #[arg(short = 'D', long, default_value = "/tmp/rustysearch.db")]
database: String, pub database_path: String,
} }

View File

@ -17,7 +17,11 @@ async fn main() -> std::io::Result<()> {
let args = Args::parse(); let args = Args::parse();
// Initialize logger // Initialize logger
env_logger::init_from_env(Env::default().default_filter_or("debug")); if args.log_level != "" {
env_logger::init_from_env(Env::default().default_filter_or(args.log_level));
} else {
env_logger::init_from_env(Env::default().default_filter_or("info"));
}
// Initialize the search engine // Initialize the search engine
let search_engine = SearchEngine::new(1.5, 0.75); let search_engine = SearchEngine::new(1.5, 0.75);