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

Function GetInputSource

cmd/gosqlx/cmd/stdin_utils.go:73–92  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

71// 2. Auto-detected piped stdin
72// 3. File path or direct SQL
73func 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

Callers 2

ReadInputWithFallbackFunction · 0.70
TestGetInputSourceFunction · 0.70

Calls 2

ReadFromStdinFunction · 0.70
DetectAndReadInputFunction · 0.70

Tested by 1

TestGetInputSourceFunction · 0.56