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

Function DetectInputMode

cmd/gosqlx/cmd/stdin_utils.go:159–178  ·  view source on GitHub ↗

DetectInputMode determines the input mode based on arguments and stdin state Returns: (useStdin bool, inputArg string, error)

(args []string)

Source from the content-addressed store, hash-verified

157// DetectInputMode determines the input mode based on arguments and stdin state
158// Returns: (useStdin bool, inputArg string, error)
159func DetectInputMode(args []string) (bool, string, error) {
160 // Case 1: Explicit stdin via "-"
161 if len(args) > 0 && args[0] == "-" {
162 return true, "-", nil
163 }
164
165 // Case 2: No arguments
166 if len(args) == 0 {
167 // Check if stdin is piped
168 if IsStdinPipe() {
169 return true, "-", nil
170 }
171 // No piped stdin and no args = error
172 return false, "", fmt.Errorf("no input provided")
173 }
174
175 // Case 3: Arguments provided
176 // Always prefer explicit arguments over stdin
177 return false, args[0], nil
178}
179
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

Callers 3

TestInputSourceDetectionFunction · 0.70
ReadInputWithFallbackFunction · 0.70
TestDetectInputModeFunction · 0.70

Calls 2

IsStdinPipeFunction · 0.70
ErrorfMethod · 0.65

Tested by 2

TestInputSourceDetectionFunction · 0.56
TestDetectInputModeFunction · 0.56