dm_database_sqllog2db/cli/
opts.rs1use clap::{CommandFactory, Parser, Subcommand};
2use clap_complete::{Shell, generate};
3
4#[derive(Debug, Parser)]
6#[command(
7 name = "sqllog2db",
8 version,
9 about = "Parse DM database SQL logs and export to CSV/JSONL/SQLite",
10 long_about = "A lightweight and efficient CLI tool for parsing DM database SQL logs (streaming) and exporting to multiple formats with error tracking."
11)]
12pub struct Cli {
13 #[arg(short = 'v', long = "verbose", global = true)]
15 pub verbose: bool,
16
17 #[arg(short = 'q', long = "quiet", global = true, conflicts_with = "verbose")]
19 pub quiet: bool,
20
21 #[command(subcommand)]
22 pub command: Option<Commands>,
23}
24
25#[derive(Debug, Subcommand)]
26pub enum Commands {
27 Run {
29 #[arg(short = 'c', long = "config", default_value = "config.toml")]
31 config: String,
32 },
33 Init {
35 #[arg(short = 'o', long = "output", default_value = "config.toml")]
37 output: String,
38 #[arg(short = 'f', long = "force")]
40 force: bool,
41 },
42 Validate {
44 #[arg(short = 'c', long = "config", default_value = "config.toml")]
46 config: String,
47 },
48 Completions {
50 #[arg(value_enum)]
52 shell: Shell,
53 },
54 SelfUpdate {
56 #[arg(short = 'k', long = "check")]
58 check: bool,
59 },
60}
61
62impl Cli {
63 pub fn generate_completions(shell: Shell) {
65 let mut cmd = Cli::command();
66 let bin_name = cmd.get_name().to_string();
67 generate(shell, &mut cmd, bin_name, &mut std::io::stdout());
68 }
69}