Diff
1diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
2new file mode 100644
3index 0000000000000000000000000000000000000000..b9e0222c802fe8ed6bbf5f794f02210bc3dfedc6
4--- /dev/null
5+++ b/.github/workflows/ci.yaml
6@@ -0,0 +1,28 @@
7+name: Run CI
8+
9+on:
10+ push:
11+ branches:
12+ - "*"
13+
14+jobs:
15+ lint_test:
16+ name: Linting and tests
17+ runs-on: ubuntu-latest
18+ permissions:
19+ contents: write
20+
21+ steps:
22+ - name: Checkout code
23+ uses: actions/checkout@v4
24+
25+ - name: Set up Go
26+ uses: actions/setup-go@v5
27+ with:
28+ go-version-file: "go.mod"
29+
30+ - name: Run linting
31+ run: "make lint"
32+
33+ - name: Run tests
34+ run: "make test"
35diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
36index ded93a536354d53833a353061d40a243a9e70629..70cb664577cb27dd6c9be66c079370eed1587fc7 100644
37--- a/.github/workflows/release.yml
38+++ b/.github/workflows/release.yml
39@@ -3,10 +3,11 @@ name: Release
40 on:
41 push:
42 tags:
43- - "*"
44+ - "v*"
45
46 jobs:
47 build_release:
48+ name: Build logfmt binaries
49 runs-on: ubuntu-latest
50 strategy:
51 matrix:
52@@ -30,7 +31,7 @@ jobs:
53 GOARCH: ${{ matrix.goarch }}
54 run: |
55 go build -ldflags="-s -w" -o logfmt-${{ matrix.goos }}-${{ matrix.goarch }}-${{ github.ref_name }}
56-
57+
58 - name: Compress with UPX (Linux only)
59 if: matrix.goos == 'linux'
60 uses: crazy-max/ghaction-upx@v3
61@@ -47,6 +48,7 @@ jobs:
62 retention-days: 1
63
64 create_release:
65+ name: Create GitHub release from tag version
66 runs-on: ubuntu-latest
67 needs: build_release
68 permissions:
69@@ -68,4 +70,4 @@ jobs:
70 name: "Release ${{ github.ref_name }}"
71 body: |
72 Automated release for tag ${{ github.ref_name }}.
73- files: release-artifacts/*/*
74+ files: release-artifacts/*/*
75diff --git a/.gitignore b/.gitignore
76new file mode 100644
77index 0000000000000000000000000000000000000000..e660fd93d3196215552065b1e63bf6a2f393ed86
78--- /dev/null
79+++ b/.gitignore
80@@ -0,0 +1 @@
81+bin/
82diff --git a/.golangci.yml b/.golangci.yml
83index 5cb0a2b1577094d6a2884a1fff78125d34ed0186..3880a3ee3092699ccabebfe92a4b00e28e819742 100644
84--- a/.golangci.yml
85+++ b/.golangci.yml
86@@ -1,22 +1,46 @@
87 ---
88+version: "2"
89 linters:
90 enable:
91- - goimports
92- - stylecheck
93+ - forbidigo
94 - lll
95+ - prealloc
96+ - predeclared
97+ - staticcheck
98 - errcheck
99-
100-run:
101- go: '1.22'
102- timeout: 30s
103-
104-issues:
105- exclude-rules:
106- - linters:
107- - lll
108- source: "// nolint:lll"
109- - linters:
110- - unused
111- - deadcode
112- - varcheck
113- source: "// nolint:unused"
114+ exclusions:
115+ generated: lax
116+ presets:
117+ - comments
118+ - common-false-positives
119+ - legacy
120+ - std-error-handling
121+ rules:
122+ - linters:
123+ - lll
124+ source: // nolint:lll
125+ - linters:
126+ - staticcheck
127+ source: // nolint:stylecheck
128+ - linters:
129+ - deadcode
130+ - revive
131+ - unused
132+ - varcheck
133+ source: // nolint:unused
134+ - linters:
135+ - staticcheck
136+ text: 'SA1019:'
137+ source: // ignore:deprecated
138+formatters:
139+ enable:
140+ - gci
141+ - gofmt
142+ - gofumpt
143+ - goimports
144+ settings:
145+ gci:
146+ sections:
147+ - standard
148+ - default
149+ - localmodule
150diff --git a/Makefile b/Makefile
151new file mode 100644
152index 0000000000000000000000000000000000000000..94376339f5d8cc92a0d86455b3c7661316de3cdd
153--- /dev/null
154+++ b/Makefile
155@@ -0,0 +1,19 @@
156+.PHONY: setup lint test
157+
158+setup: bin/golangci-lint
159+ go mod download
160+
161+bin:
162+ mkdir bin
163+
164+bin/golangci-lint: bin
165+ GOBIN=$(PWD)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.0
166+
167+lint: bin/golangci-lint
168+ bin/golangci-lint fmt
169+ go vet ./...
170+ go mod tidy
171+ bin/golangci-lint -c .golangci.yml run ./...
172+
173+test:
174+ go test -timeout=10s -race -cover ./...
175diff --git a/config/config.go b/config/config.go
176index 60995d0d9b6e4184f0b285816721ebd9185db28c..3aa6fa3b633c8642cc35d618f1596103653e0185 100644
177--- a/config/config.go
178+++ b/config/config.go
179@@ -44,9 +44,9 @@ type rawConfig struct {
180 NoColor bool `long:"no-color" short:"n" description:"Disable color output"`
181 ForceColor bool `long:"force-color" short:"c" description:"Force color output, even when outputting to a pipe"`
182 NoTime bool `long:"no-time" short:"t" description:"Disable time output"`
183- KeepEmpty bool `long:"keep-empty" short:"k" description:"Keep lines with no field present selected by output or with all excluded"`
184- Raw bool `long:"raw" short:"r" description:"Output only selected fields values (comma separated) lcut like"`
185- All bool `long:"all" short:"A" description:"Output all field after the output fields effectivly making it ordered"`
186+ KeepEmpty bool `long:"keep-empty" short:"k" description:"Keep lines with no field present selected by output or with all excluded"` // nolint:lll
187+ Raw bool `long:"raw" short:"r" description:"Output only selected fields values (comma separated) lcut like"` // nolint:lll
188+ All bool `long:"all" short:"A" description:"Output all field after the output fields effectivly making it ordered"` // nolint:lll
189 }
190
191 func Parse() (*Config, error) {
192diff --git a/parser/record.go b/parser/record.go
193index 0f5d73a554300b6cbb9b3a3f6c8cf1a147c6875f..500dba5253e3adee84bec4606fafeb2bf1c5c481 100644
194--- a/parser/record.go
195+++ b/parser/record.go
196@@ -7,9 +7,10 @@ import (
197 "strings"
198 "time"
199
200- "github.com/TheEdgeOfRage/logfmt/config"
201 "github.com/fatih/color"
202 "github.com/go-logfmt/logfmt"
203+
204+ "github.com/TheEdgeOfRage/logfmt/config"
205 )
206
207 var (
208@@ -155,7 +156,7 @@ func (r *Record) String(cfg *config.Config) string {
209 outFields := r.fieldOrder
210 if len(cfg.OutputFields) > 0 {
211 if cfg.All {
212- var reorderedFields []string = cfg.OutputFields
213+ reorderedFields := cfg.OutputFields
214
215 for _, key := range r.fieldOrder {
216 if !slices.Contains(reorderedFields, key) {