Skip to main content

dm_database_sqllog2db/cli/
opts.rs

1use clap::{CommandFactory, Parser, Subcommand};
2use clap_complete::{Shell, generate};
3
4/// SQL log exporter tool for DM database
5#[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    /// Enable verbose output (debug level)
14    #[arg(short = 'v', long = "verbose", global = true)]
15    pub verbose: bool,
16
17    /// Suppress non-error output (error level only)
18    #[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 the log export task
28    Run {
29        /// Configuration file path
30        #[arg(short = 'c', long = "config", default_value = "config.toml")]
31        config: String,
32    },
33    /// Generate a default configuration file
34    Init {
35        /// Output configuration file path
36        #[arg(short = 'o', long = "output", default_value = "config.toml")]
37        output: String,
38        /// Force overwrite if file exists
39        #[arg(short = 'f', long = "force")]
40        force: bool,
41    },
42    /// Validate a configuration file
43    Validate {
44        /// Configuration file path
45        #[arg(short = 'c', long = "config", default_value = "config.toml")]
46        config: String,
47    },
48    /// Generate shell completion scripts
49    Completions {
50        /// Shell type to generate completions for
51        #[arg(value_enum)]
52        shell: Shell,
53    },
54    /// Self-update the application to the latest version
55    SelfUpdate {
56        /// Check for updates without performing the update
57        #[arg(short = 'k', long = "check")]
58        check: bool,
59    },
60}
61
62impl Cli {
63    /// Generate shell completions
64    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}