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

Function ReadInputWithFallback

cmd/gosqlx/cmd/stdin_utils.go:182–210  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
182func 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.

Callers

nothing calls this directly

Calls 5

DetectInputModeFunction · 0.70
ReadFromStdinFunction · 0.70
ValidateStdinInputFunction · 0.70
GetInputSourceFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected