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

Function parseRun

cmd/gosqlx/cmd/parse.go:60–112  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

58}
59
60func parseRun(cmd *cobra.Command, args []string) error {
61 // Handle stdin input
62 if len(args) == 0 || (len(args) == 1 && args[0] == "-") {
63 if ShouldReadFromStdin(args) {
64 return parseFromStdin(cmd)
65 }
66 return fmt.Errorf("no input provided: specify file path, SQL query, or pipe via stdin")
67 }
68
69 // Load configuration with CLI flag overrides
70 cfg, err := config.LoadDefault()
71 if err != nil {
72 // If config load fails, use defaults
73 cfg = config.DefaultConfig()
74 }
75
76 // Track which flags were explicitly set
77 flagsChanged := make(map[string]bool)
78 cmd.Flags().Visit(func(f *pflag.Flag) {
79 flagsChanged[f.Name] = true
80 })
81 if cmd.Parent() != nil && cmd.Parent().PersistentFlags() != nil {
82 cmd.Parent().PersistentFlags().Visit(func(f *pflag.Flag) {
83 flagsChanged[f.Name] = true
84 })
85 }
86
87 // Create parser options from config and flags
88 opts := ParserOptionsFromConfig(cfg, flagsChanged, ParserFlags{
89 ShowAST: parseShowAST,
90 ShowTokens: parseShowTokens,
91 TreeView: parseTreeView,
92 Format: format,
93 Verbose: verbose,
94 })
95
96 // Create parser with injectable output writers
97 parser := NewParser(cmd.OutOrStdout(), cmd.ErrOrStderr(), opts)
98
99 // Run parsing
100 result, err := parser.Parse(args[0])
101 if err != nil {
102 return err
103 }
104
105 // CRITICAL: Always release AST if it was created
106 if result.AST != nil {
107 defer ast.ReleaseAST(result.AST)
108 }
109
110 // Display the result
111 return parser.Display(result)
112}
113
114// parseFromStdin handles parsing from stdin input
115func parseFromStdin(cmd *cobra.Command) error {

Callers

nothing calls this directly

Calls 11

ParseMethod · 0.95
DisplayMethod · 0.95
LoadDefaultFunction · 0.92
DefaultConfigFunction · 0.92
ReleaseASTFunction · 0.92
parseFromStdinFunction · 0.85
ParserOptionsFromConfigFunction · 0.85
ShouldReadFromStdinFunction · 0.70
NewParserFunction · 0.70
ErrorfMethod · 0.65
VisitMethod · 0.65

Tested by

no test coverage detected