GetInputSource determines the source of input and returns the content Supports three modes: 1. Explicit stdin via "-" argument 2. Auto-detected piped stdin 3. File path or direct SQL
(arg string)
| 71 | // 2. Auto-detected piped stdin |
| 72 | // 3. File path or direct SQL |
| 73 | func GetInputSource(arg string) (*InputResult, error) { |
| 74 | // Mode 1: Explicit stdin via "-" argument |
| 75 | if arg == "-" { |
| 76 | content, err := ReadFromStdin() |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | return &InputResult{ |
| 81 | Type: InputTypeSQL, |
| 82 | Content: content, |
| 83 | Source: "stdin", |
| 84 | }, nil |
| 85 | } |
| 86 | |
| 87 | // Mode 2: Auto-detect piped stdin (when no args or args look like flags) |
| 88 | // This is handled by the caller checking IsStdinPipe() before calling this |
| 89 | |
| 90 | // Mode 3: File path or direct SQL (existing behavior) |
| 91 | return DetectAndReadInput(arg) |
| 92 | } |
| 93 | |
| 94 | // WriteOutput writes content to the specified output destination |
| 95 | // Handles stdout and file output with broken pipe detection |