ReadInputWithFallback tries to read from the specified source with stdin fallback This provides a convenient way to handle both file and stdin inputs
(args []string)
| 180 | // ReadInputWithFallback tries to read from the specified source with stdin fallback |
| 181 | // This provides a convenient way to handle both file and stdin inputs |
| 182 | func ReadInputWithFallback(args []string) (*InputResult, error) { |
| 183 | // Detect input mode |
| 184 | useStdin, inputArg, err := DetectInputMode(args) |
| 185 | if err != nil { |
| 186 | return nil, err |
| 187 | } |
| 188 | |
| 189 | // If using stdin, read from it |
| 190 | if useStdin { |
| 191 | content, err := ReadFromStdin() |
| 192 | if err != nil { |
| 193 | return nil, err |
| 194 | } |
| 195 | |
| 196 | // Validate stdin content |
| 197 | if err := ValidateStdinInput(content); err != nil { |
| 198 | return nil, fmt.Errorf("stdin validation failed: %w", err) |
| 199 | } |
| 200 | |
| 201 | return &InputResult{ |
| 202 | Type: InputTypeSQL, |
| 203 | Content: content, |
| 204 | Source: "stdin", |
| 205 | }, nil |
| 206 | } |
| 207 | |
| 208 | // Otherwise, use the provided argument |
| 209 | return GetInputSource(inputArg) |
| 210 | } |
| 211 | |
| 212 | // ShouldReadFromStdin determines if we should read from stdin based on args. |
| 213 | // Returns true only when stdin actually has piped data available. |
nothing calls this directly
no test coverage detected