(cmd *cobra.Command, args []string)
| 58 | } |
| 59 | |
| 60 | func 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 |
| 115 | func parseFromStdin(cmd *cobra.Command) error { |
nothing calls this directly
no test coverage detected