feat: add command line arguments

This commit is contained in:
Alex Wellnitz
2024-02-16 20:55:26 +01:00
parent 45c1aa471a
commit 41824bd04b
8 changed files with 157 additions and 3 deletions

17
src/cmd/arguments.rs Normal file
View File

@@ -0,0 +1,17 @@
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
/// Config file path
#[arg(short, long, default_value = "/etc/rustysearch/config.json")]
config: String,
/// Change the log level
#[arg(short = 'l', long, default_value = "info")]
loglevel: String,
/// Change Database path
#[arg(short = 'D', long, default_value = "/tmp/rustysearch.db")]
database: String,
}

1
src/cmd/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod arguments;

View File

@@ -1,3 +1,4 @@
pub mod search;
pub mod cmd;
pub mod handlers;
pub mod types;
pub mod search;
pub mod types;

View File

@@ -1,9 +1,11 @@
use std::sync::Mutex;
use actix_web::{middleware::Logger, web, App, HttpServer};
use clap::Parser;
use env_logger::Env;
use rustysearch::{
cmd::arguments::Args,
handlers::{hello, search},
search::engine::SearchEngine,
types::app_state::AppStateWithSearchEngine,
@@ -11,6 +13,8 @@ use rustysearch::{
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let args = Args::parse();
// Initialize logger
env_logger::init_from_env(Env::default().default_filter_or("debug"));

16
src/types/config.rs Normal file
View File

@@ -0,0 +1,16 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
http_addr: String,
database_path: String,
}
impl Config {
pub fn new() -> Config {
Config {
http_addr: String::from("127.0.0.1:4000"),
database_path: String::from("/tmp/rustysearch.db"),
}
}
}

View File

@@ -1 +1,2 @@
pub mod app_state;
pub mod app_state;
pub mod config;