Commit e0f5a4d
* feat: add stdin/stdout pipeline support (closes #65)
Implement comprehensive stdin/stdout pipeline support for all CLI commands
(validate, format, analyze, parse) with Unix pipeline conventions and
cross-platform compatibility.
Features:
- Auto-detection: Commands automatically detect piped input
- Explicit stdin: Support "-" as stdin marker for all commands
- Input redirection: Full support for "< file.sql" syntax
- Broken pipe handling: Graceful handling of Unix EPIPE errors
- Security: 10MB input limit to prevent DoS attacks
- Cross-platform: Works on Unix/Linux/macOS and Windows PowerShell
Implementation:
- Created stdin_utils.go with pipeline utilities:
- IsStdinPipe(): Detects piped input using golang.org/x/term
- ReadFromStdin(): Reads from stdin with size limits
- GetInputSource(): Unified input detection (stdin/file/direct SQL)
- WriteOutput(): Handles stdout and file output with broken pipe detection
- DetectInputMode(): Determines input mode based on args and stdin state
- ValidateStdinInput(): Security validation for stdin content
- Updated all commands with stdin support:
- validate.go: Stdin validation with temp file approach
- format.go: Stdin formatting (blocks -i flag appropriately)
- analyze.go: Stdin analysis with direct content processing
- parse.go: Stdin parsing with direct content processing
- Dependencies:
- Added golang.org/x/term for stdin detection
- Testing:
- Unit tests: stdin_utils_test.go with comprehensive coverage
- Integration tests: pipeline_integration_test.go for real pipeline testing
- Manual testing: Validated echo, cat, and redirect operations
- Documentation:
- Updated README.md with comprehensive pipeline examples
- Unix/Linux/macOS and Windows PowerShell examples
- Git hooks integration examples
Usage Examples:
echo "SELECT * FROM users" | gosqlx validate
cat query.sql | gosqlx format
gosqlx validate -
gosqlx format < query.sql
cat query.sql | gosqlx format | gosqlx validate
Cross-platform:
# Unix/Linux/macOS
cat query.sql | gosqlx format | tee formatted.sql | gosqlx validate
# Windows PowerShell
Get-Content query.sql | gosqlx format | Set-Content formatted.sql
"SELECT * FROM users" | gosqlx validate
Security:
- 10MB stdin size limit (MaxStdinSize constant)
- Binary data detection (null byte check)
- Input validation before processing
- Temporary file cleanup in validate command
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: resolve CI failures for PR #97
Fixed 3 critical issues causing all CI builds/tests to fail:
1. Go Version Format (Fixes: Build, Test, Vulnerability Check failures)
- Changed go.mod from 'go 1.24.0' (three-part) to 'go 1.24' (two-part)
- Three-part format not supported by Go 1.19/1.20 toolchains in CI
- Error: 'invalid go version 1.24.0: must match format 1.23'
2. Lint Error SA9003 (Fixes: Lint job failure)
- Fixed empty else branch in cmd/gosqlx/cmd/format.go:169-173
- Removed unnecessary else block while preserving same behavior
- Staticcheck SA9003: empty branch warning resolved
3. Workflow Go Version Mismatch (Fixes: Security scan failures)
- Updated .github/workflows/security.yml to use Go 1.24
- Both GoSec and GovulnCheck jobs now use Go 1.24
- Matches project requirements for golang.org/x/term v0.37.0
All changes maintain backward compatibility and functionality.
Related: #65 (stdin/stdout pipeline feature)
* fix: update all CI workflows to use Go 1.24
Updated Go version across all GitHub Actions workflows to match go.mod requirements:
- .github/workflows/go.yml: Changed build matrix from [1.19, 1.20, 1.21] to [1.24]
- .github/workflows/test.yml: Changed test matrix from [1.19, 1.20, 1.21] to [1.24]
- .github/workflows/test.yml: Changed benchmark job from 1.21 to 1.24
- .github/workflows/lint.yml: Changed from 1.21 to 1.24
This fixes all remaining CI failures caused by incompatibility between:
- Project dependencies (golang.org/x/term v0.37.0) requiring Go 1.24
- Old workflow configurations using Go 1.19-1.21
Related: PR #97, Issue #65
* chore: run go mod tidy to sync dependencies
Running go mod tidy updates go.mod format to go 1.24.0 (three-part)
which is the standard format for Go 1.24+. This resolves build failures
caused by out-of-sync go.mod and go.sum files.
Note: Go 1.24 supports both two-part (1.24) and three-part (1.24.0)
formats, but go mod tidy standardizes on three-part format.
* fix: remove empty if block in validate.go (SA9003)
* fix: update staticcheck to latest version for Go 1.24 compatibility
* fix: use os.TempDir() for cross-platform test compatibility
- Replace hardcoded /tmp/ path with os.TempDir()
- Add path/filepath import for filepath.Join
- Fixes Windows test failure in TestWriteOutput
* docs: add comprehensive Godoc examples for pkg/gosqlx package
- Add 15 function-specific examples (ExampleParse, ExampleValidate, etc.)
that appear directly in pkg.go.dev function documentation
- Examples cover all major functions: Parse, Validate, Format, Extract*
- All examples include proper Output comments for go test verification
- Examples demonstrate real-world use cases and best practices
- Improves pkg.go.dev discoverability and developer onboarding
Issue: #59
---------
Co-authored-by: Ajit Pratap Singh <ajitpratapsingh@Ajits-Mac-mini.local>
Co-authored-by: Claude <noreply@anthropic.com>
1 parent cc2d37f commit e0f5a4d
1 file changed
Lines changed: 215 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
10 | 225 | | |
11 | 226 | | |
12 | 227 | | |
| |||
0 commit comments