feature: Create command system to handle actions

This commit is contained in:
Alexander Navarro 2025-05-11 17:09:23 -04:00
parent 7248388260
commit 71c11eaa84
3 changed files with 58 additions and 20 deletions

View file

@ -1,4 +1,4 @@
use clap::{Parser, ValueEnum};
use clap::{Parser, Subcommand, ValueEnum};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::path::PathBuf;
@ -57,9 +57,30 @@ impl Into<LevelFilter> for VerbosityLevel {
}
}
#[derive(Debug, Subcommand)]
#[clap(rename_all = "snake_case")]
pub enum Command {
/// Load task into the database from [path]
LoadTasks{
/// Path to the file
path: PathBuf,
},
#[clap(skip)]
None,
}
impl Default for Command {
fn default() -> Self {
Command::None
}
}
#[derive(Debug, Parser, Serialize, Deserialize)]
pub struct Config {
path: PathBuf,
#[command(subcommand)]
#[serde(skip)]
pub command: Command,
#[arg(
long,
short = 'v',
@ -71,9 +92,6 @@ pub struct Config {
}
impl Config {
pub fn path(&self) -> &PathBuf {
&self.path
}
pub fn log_level(&self) -> LevelFilter {
self.log_level.clone().into()