feat(configuration): Add global configuration
also update some error messages
This commit is contained in:
parent
8cd4b4b10f
commit
f0485abfbb
6 changed files with 67 additions and 22 deletions
46
src/configuration.rs
Normal file
46
src/configuration.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use clap::Parser;
|
||||
use lazy_static::lazy_static;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: Config = Config::new();
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(help = "Directory to scan for files")]
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
pub base_path: PathBuf,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
base_path: env::current_dir().expect("Current directory is not available."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Self {
|
||||
let mut config = Self::default();
|
||||
|
||||
let cli = Self::get_cli_args();
|
||||
|
||||
if let Some(path) = cli.path {
|
||||
config.base_path = path;
|
||||
}
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
fn get_cli_args() -> Args {
|
||||
Args::parse()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue