sqruff_cli_lib/
commands.rs1use std::path::PathBuf;
2use strum_macros::Display;
3
4use clap::{Parser, Subcommand, ValueEnum};
5
6use crate::github_action::is_in_github_action;
7
8#[derive(Debug, Parser)]
9#[command(name = "sqruff")]
10#[command(about = "sqruff is a sql formatter and linter", long_about = None, version=env!("CARGO_PKG_VERSION")
11)]
12pub struct Cli {
13 #[command(subcommand)]
14 pub command: Commands,
15 #[arg(long, global = true)]
17 pub config: Option<String>,
18 #[arg(long, global = true, default_value = "false")]
20 pub parsing_errors: bool,
21}
22
23#[derive(Debug, Subcommand)]
24pub enum Commands {
25 #[command(
26 name = "lint",
27 about = "Lint SQL files via passing a list of files or using stdin"
28 )]
29 Lint(LintArgs),
30 #[command(
31 name = "fix",
32 about = "Fix SQL files via passing a list of files or using stdin"
33 )]
34 Fix(FixArgs),
35 #[command(name = "lsp", about = "Run an LSP server")]
36 Lsp,
37 #[command(
38 name = "info",
39 about = "Print information about sqruff and the current environment"
40 )]
41 Info,
42 #[command(name = "rules", about = "Explain the available rules")]
43 Rules,
44}
45
46#[derive(Debug, Parser)]
47pub struct LintArgs {
48 pub paths: Vec<PathBuf>,
50 #[arg(default_value_t, short, long)]
51 pub format: Format,
52}
53
54#[derive(Debug, Parser)]
55pub struct FixArgs {
56 pub paths: Vec<PathBuf>,
58 #[arg(default_value_t, short, long)]
60 pub format: Format,
61}
62
63#[derive(Debug, Clone, Copy, ValueEnum, Display)]
64#[strum(serialize_all = "kebab-case")]
65pub enum Format {
66 Human,
67 GithubAnnotationNative,
68 Json,
69}
70
71impl Default for Format {
72 fn default() -> Self {
73 if is_in_github_action() {
74 Format::GithubAnnotationNative
75 } else {
76 Format::Human
77 }
78 }
79}