feat: add command line arguments
This commit is contained in:
17
src/cmd/arguments.rs
Normal file
17
src/cmd/arguments.rs
Normal 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
1
src/cmd/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod arguments;
|
@@ -1,3 +1,4 @@
|
||||
pub mod search;
|
||||
pub mod cmd;
|
||||
pub mod handlers;
|
||||
pub mod types;
|
||||
pub mod search;
|
||||
pub mod types;
|
||||
|
@@ -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
16
src/types/config.rs
Normal 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"),
|
||||
}
|
||||
}
|
||||
}
|
@@ -1 +1,2 @@
|
||||
pub mod app_state;
|
||||
pub mod app_state;
|
||||
pub mod config;
|
||||
|
Reference in New Issue
Block a user