1pub mod cli;
2pub mod core;
3pub mod io;
4pub mod logging;
5
6use anyhow::{Ok, Result};
7
8use clap::Parser as _;
9use cli::cmd::Commands;
10use io::env::{ContextWriter, WEnv};
11
12use crate::cli::cmd::{pipe_command, Cli};
13use crate::core::action::*;
14
15use crate::logging::logger::show_config;
16
17pub fn run() -> Result<()> {
18 let piped_commands = pipe_command()?;
19
20 let cli = Cli::parse();
21
22 let current_env = WEnv::Prod;
23
24 let init_dir = ContextWriter { env: WEnv::Prod };
25
26 init_dir.init()?;
27
28 let config = current_env.config();
29 let file_format: &String = &config.file_format;
30
31 match &cli.command {
32 Some(Commands::Add { note, file }) => {
33 let file_name = match file {
34 Some(file_name) => file_name.clone(),
35 _ => "my_notes".to_string(),
36 };
37 add(note, &file_name, file_format, ¤t_env)?;
38 Ok(())
39 }
40 Some(Commands::Show { file, complete }) => {
41 let is_complete = complete.is_some();
42 show(file, &is_complete, ¤t_env)?;
43
44 Ok(())
45 }
46 Some(Commands::List { short }) => {
47 let is_short = short.unwrap_or(false);
48 list(is_short, ¤t_env)?;
49 Ok(())
50 }
51 Some(Commands::Delete { file }) => {
52 delete(file, file_format, ¤t_env)?;
53 Ok(())
54 }
55 Some(Commands::Purge {}) => {
56 purge(¤t_env)?;
57 Ok(())
58 }
59 Some(Commands::Pa { file }) => {
60 let file_name = match file {
61 Some(file_name) => file_name.clone(),
62 _ => "my_notes".to_string(),
63 };
64 add(&piped_commands, &file_name, file_format, ¤t_env)?;
65 Ok(())
66 }
67 Some(Commands::Config {}) => {
68 show_config("Current configuration: ".to_string(), config.to_string());
69 Ok(())
70 }
71 _ => unreachable!(),
72 }
73}