101 lines
2.2 KiB
Rust
101 lines
2.2 KiB
Rust
use clap::{Parser, Subcommand, ValueEnum};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::fmt;
|
|
use std::path::PathBuf;
|
|
use tracing_core::LevelFilter;
|
|
|
|
#[derive(ValueEnum, Clone, Debug, Deserialize, Serialize)]
|
|
pub enum VerbosityLevel {
|
|
Off,
|
|
Error,
|
|
Warn,
|
|
Info,
|
|
Debug,
|
|
Trace,
|
|
}
|
|
|
|
impl Default for VerbosityLevel {
|
|
fn default() -> Self {
|
|
VerbosityLevel::Error
|
|
}
|
|
}
|
|
impl fmt::Display for VerbosityLevel {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
VerbosityLevel::Off => {
|
|
write!(f, "off")
|
|
}
|
|
VerbosityLevel::Error => {
|
|
write!(f, "error")
|
|
}
|
|
VerbosityLevel::Warn => {
|
|
write!(f, "warn")
|
|
}
|
|
VerbosityLevel::Info => {
|
|
write!(f, "info")
|
|
}
|
|
VerbosityLevel::Debug => {
|
|
write!(f, "debug")
|
|
}
|
|
VerbosityLevel::Trace => {
|
|
write!(f, "trace")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Into<LevelFilter> for VerbosityLevel {
|
|
fn into(self) -> LevelFilter {
|
|
match self {
|
|
VerbosityLevel::Off => LevelFilter::OFF,
|
|
VerbosityLevel::Error => LevelFilter::ERROR,
|
|
VerbosityLevel::Warn => LevelFilter::WARN,
|
|
VerbosityLevel::Info => LevelFilter::INFO,
|
|
VerbosityLevel::Debug => LevelFilter::DEBUG,
|
|
VerbosityLevel::Trace => LevelFilter::TRACE,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[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,
|
|
},
|
|
Query,
|
|
Run,
|
|
#[clap(skip)]
|
|
None,
|
|
}
|
|
|
|
impl Default for Command {
|
|
fn default() -> Self {
|
|
Command::None
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Parser, Serialize, Deserialize)]
|
|
pub struct Config {
|
|
#[command(subcommand)]
|
|
#[serde(skip)]
|
|
pub command: Command,
|
|
|
|
#[arg(
|
|
long,
|
|
short = 'v',
|
|
default_value_t,
|
|
global = true,
|
|
help = "Increase logging verbosity"
|
|
)]
|
|
log_level: VerbosityLevel,
|
|
}
|
|
|
|
impl Config {
|
|
|
|
pub fn log_level(&self) -> LevelFilter {
|
|
self.log_level.clone().into()
|
|
}
|
|
}
|