2023-07-01 04:43:18 +00:00
|
|
|
use arguments::{Arguments, Commands};
|
|
|
|
use clap::Parser;
|
2023-07-01 06:12:55 +00:00
|
|
|
use commands::{add, print, remove};
|
2023-07-02 02:49:48 +00:00
|
|
|
use shared::{directories, errors::Error};
|
2023-07-03 02:46:19 +00:00
|
|
|
use std::path::Path;
|
2023-07-01 04:43:18 +00:00
|
|
|
|
|
|
|
mod arguments;
|
|
|
|
mod commands;
|
2023-07-02 02:49:48 +00:00
|
|
|
mod logging;
|
2023-07-01 04:43:18 +00:00
|
|
|
|
2023-07-02 01:27:03 +00:00
|
|
|
fn main() -> Result<(), Error> {
|
2023-07-02 02:49:48 +00:00
|
|
|
logging::initialize_logger()?;
|
|
|
|
|
|
|
|
let default_path = directories::get_names_path()?;
|
2023-07-01 04:43:18 +00:00
|
|
|
let args = Arguments::parse();
|
2023-07-03 23:19:45 +00:00
|
|
|
let separator = args.separator.unwrap_or(": ".into());
|
2023-07-02 01:27:03 +00:00
|
|
|
|
|
|
|
let path = match &args.path {
|
|
|
|
Some(path) => Path::new(path),
|
|
|
|
None => &default_path,
|
|
|
|
};
|
2023-07-01 04:43:18 +00:00
|
|
|
|
|
|
|
match &args.command {
|
2023-07-03 02:46:19 +00:00
|
|
|
Commands::Print {
|
|
|
|
filter,
|
|
|
|
group,
|
|
|
|
json,
|
2023-07-03 23:19:45 +00:00
|
|
|
} => print(path, filter, group, &separator, *json)?,
|
|
|
|
Commands::Add { url, name } => add(path, url, name, &separator)?,
|
|
|
|
Commands::Remove { url } => remove(path, url, &separator)?,
|
2023-07-01 06:12:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(())
|
2023-07-01 04:43:18 +00:00
|
|
|
}
|