use std::fmt::Display;
use clap::{Parser, Subcommand};
use log::LevelFilter;
use crate::property_file_reader::Delimiter;
#[derive(Parser, Debug)]
#[command(
author,
version,
about,
long_about = "Procon (Pro)perty (Con)verter \
\nA programm to convert between different property formats.
\nProperty -> Json
\nProperty -> Yaml
\nJson -> Property
\nJson -> Yaml
\nYaml -> Property *not yet implemented
\nYaml-> Yaml *not yet implemented
"
)]
pub struct Args {
#[command(subcommand)]
pub command: Command,
#[arg(short, long, default_value_t = false)]
pub dry_run: bool,
#[arg(short, long, default_value_t = LevelFilter::Info)]
pub log_level: LevelFilter,
#[arg(short, long)]
pub output_filename: Option<String>,
}
#[derive(Subcommand, Debug)]
pub enum Command {
Properties {
#[arg(short, long, default_value_t = Delimiter::Equals)]
property_delimiter: Delimiter,
filename: String,
},
Json {
filename: String,
},
Yaml {
filename: String,
},
}
impl Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
#[allow(dead_code)]
impl Command {
pub fn filename(&self) -> String {
match self {
Command::Properties { filename, .. } => filename.to_string(),
Command::Json { filename, .. } => filename.to_string(),
Command::Yaml { filename, .. } => filename.to_string(),
}
}
pub fn delimiter(&self) -> Option<&Delimiter> {
match self {
Command::Properties {
property_delimiter, ..
} => Some(property_delimiter),
Command::Json { .. } => None,
Command::Yaml { .. } => None,
}
}
}