(cmd *cobra.Command, args []string)
| 71 | } |
| 72 | |
| 73 | func validateRun(cmd *cobra.Command, args []string) error { |
| 74 | cmd.SilenceUsage = true |
| 75 | |
| 76 | // --list-dialects: print all valid dialects and exit. |
| 77 | if validateListDialects { |
| 78 | for _, d := range keywords.AllDialects() { |
| 79 | fmt.Fprintln(cmd.OutOrStdout(), string(d)) |
| 80 | } |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | // In quiet/check mode, silence all cobra output - only exit code matters |
| 85 | if validateQuiet { |
| 86 | cmd.SilenceErrors = true |
| 87 | cmd.SilenceUsage = true |
| 88 | } |
| 89 | |
| 90 | // Reject unknown dialect names early before any parsing. |
| 91 | if validateDialect != "" && !keywords.IsValidDialect(validateDialect) { |
| 92 | return fmt.Errorf("unknown SQL dialect %q; valid dialects: postgresql, mysql, mariadb, sqlserver, oracle, sqlite, snowflake, bigquery, redshift", validateDialect) |
| 93 | } |
| 94 | |
| 95 | // Handle stdin input |
| 96 | if ShouldReadFromStdin(args) { |
| 97 | return validateFromStdin(cmd) |
| 98 | } |
| 99 | |
| 100 | // Validate that we have file arguments if not using stdin |
| 101 | if len(args) == 0 { |
| 102 | return fmt.Errorf("no input provided: specify file paths or pipe SQL via stdin") |
| 103 | } |
| 104 | |
| 105 | // If single argument that looks like inline SQL (not a file), validate it directly |
| 106 | if len(args) == 1 { |
| 107 | if _, err := os.Stat(args[0]); err != nil && looksLikeSQL(args[0]) { |
| 108 | return validateInlineSQL(cmd, args[0]) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Load configuration with CLI flag overrides |
| 113 | cfg, err := config.LoadDefault() |
| 114 | if err != nil { |
| 115 | // If config load fails, use defaults |
| 116 | cfg = config.DefaultConfig() |
| 117 | } |
| 118 | |
| 119 | // Validate output format |
| 120 | if validateOutputFormat != "" && validateOutputFormat != OutputFormatText && validateOutputFormat != OutputFormatJSON && validateOutputFormat != OutputFormatSARIF { |
| 121 | return fmt.Errorf("invalid output format: %s (valid options: %s, %s, %s)", validateOutputFormat, OutputFormatText, OutputFormatJSON, OutputFormatSARIF) |
| 122 | } |
| 123 | |
| 124 | // Track which flags were explicitly set |
| 125 | flagsChanged := trackChangedFlags(cmd) |
| 126 | |
| 127 | // Create validator options from config and flags |
| 128 | // When outputting SARIF or JSON, automatically enable quiet mode to avoid mixing output |
| 129 | quietMode := validateQuiet || validateOutputFormat == OutputFormatSARIF || validateOutputFormat == OutputFormatJSON |
| 130 |
nothing calls this directly
no test coverage detected