log: Add structs for cli arguments and configuration
This commit is contained in:
parent
e32d6ce118
commit
c078a13c8e
1 changed files with 42 additions and 0 deletions
42
labadoor-log/src/cli.rs
Normal file
42
labadoor-log/src/cli.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use clap::{Parser, ValueEnum};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Parser, Debug)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
#[arg(short, long, value_enum)]
|
||||
pub backends: Option<Vec<Backend>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Parser, ValueEnum, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Backend {
|
||||
#[cfg(feature = "csv")]
|
||||
CSV,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Parser, Debug)]
|
||||
pub enum Command {
|
||||
Append(Append),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Parser, Debug)]
|
||||
pub struct Append {
|
||||
pub time: String,
|
||||
pub username: String,
|
||||
pub resource: String,
|
||||
pub method: String,
|
||||
}
|
||||
|
||||
pub fn parse() -> Cli {
|
||||
Cli::parse()
|
||||
}
|
||||
|
||||
#[cfg(feature = "csv")]
|
||||
#[derive(Deserialize, Parser, Debug)]
|
||||
pub struct CSV {
|
||||
#[clap(short, long)]
|
||||
#[arg(default_value = "Some(String::from(\"/etc/labadoor\"))")]
|
||||
pub path: String,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue