MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / formatInlineSQL

Function formatInlineSQL

cmd/gosqlx/cmd/format.go:199–232  ·  view source on GitHub ↗

formatInlineSQL formats inline SQL passed as a command argument

(cmd *cobra.Command, sql string)

Source from the content-addressed store, hash-verified

197
198// formatInlineSQL formats inline SQL passed as a command argument
199func 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
234func init() {
235 rootCmd.AddCommand(formatCmd)

Callers 1

formatRunFunction · 0.85

Calls 8

formatSQLMethod · 0.95
LoadDefaultFunction · 0.92
DefaultConfigFunction · 0.92
trackChangedFlagsFunction · 0.85
NewFormatterFunction · 0.70
WriteOutputFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected