use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{Shell, generate};
#[derive(Debug, Parser)]
#[command(
name = "sqllog2db",
version,
about = "Parse DM database SQL logs and export to CSV/Parquet/JSONL/SQLite/DuckDB/PostgreSQL/DM",
long_about = "A lightweight and efficient CLI tool for parsing DM database SQL logs (streaming) and exporting to multiple formats with error tracking."
)]
pub struct Cli {
#[arg(short = 'v', long = "verbose", global = true)]
pub verbose: bool,
#[arg(short = 'q', long = "quiet", global = true, conflicts_with = "verbose")]
pub quiet: bool,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Debug, Subcommand)]
pub enum Commands {
Run {
#[arg(short = 'c', long = "config", default_value = "config.toml")]
config: String,
#[cfg(feature = "tui")]
#[arg(long = "tui")]
use_tui: bool,
},
Init {
#[arg(short = 'o', long = "output", default_value = "config.toml")]
output: String,
#[arg(short = 'f', long = "force")]
force: bool,
},
Validate {
#[arg(short = 'c', long = "config", default_value = "config.toml")]
config: String,
},
Completions {
#[arg(value_enum)]
shell: Shell,
},
}
impl Cli {
pub fn generate_completions(shell: Shell) {
let mut cmd = Cli::command();
let bin_name = cmd.get_name().to_string();
generate(shell, &mut cmd, bin_name, &mut std::io::stdout());
}
}