formatInlineSQL formats inline SQL passed as a command argument
(cmd *cobra.Command, sql string)
| 197 | |
| 198 | // formatInlineSQL formats inline SQL passed as a command argument |
| 199 | func formatInlineSQL(cmd *cobra.Command, sql string) error { |
| 200 | // Load configuration |
| 201 | cfg, err := config.LoadDefault() |
| 202 | if err != nil { |
| 203 | cfg = config.DefaultConfig() |
| 204 | } |
| 205 | |
| 206 | // Track which flags were explicitly set |
| 207 | flagsChanged := trackChangedFlags(cmd) |
| 208 | |
| 209 | opts := FormatterOptionsFromConfig(cfg, flagsChanged, FormatterFlags{ |
| 210 | InPlace: false, |
| 211 | IndentSize: formatIndentSize, |
| 212 | Uppercase: formatUppercase, |
| 213 | Compact: formatCompact, |
| 214 | Check: formatCheck, |
| 215 | MaxLine: formatMaxLine, |
| 216 | Verbose: verbose, |
| 217 | Output: outputFile, |
| 218 | }) |
| 219 | |
| 220 | formatter := NewFormatter(cmd.OutOrStdout(), cmd.ErrOrStderr(), opts) |
| 221 | formattedSQL, err := formatter.formatSQL(sql) |
| 222 | if err != nil { |
| 223 | return fmt.Errorf("formatting failed: %w", err) |
| 224 | } |
| 225 | |
| 226 | // Ensure trailing newline |
| 227 | if !strings.HasSuffix(formattedSQL, "\n") { |
| 228 | formattedSQL += "\n" |
| 229 | } |
| 230 | |
| 231 | return WriteOutput([]byte(formattedSQL), outputFile, cmd.OutOrStdout()) |
| 232 | } |
| 233 | |
| 234 | func init() { |
| 235 | rootCmd.AddCommand(formatCmd) |
no test coverage detected