Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run CI

on:
push:
branches:
- "*"

jobs:
lint_test:
name: Linting and tests
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Run linting
run: "make lint"

- name: Run tests
run: "make test"
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ name: Release
on:
push:
tags:
- "*"
- "v*"

jobs:
build_release:
name: Build logfmt binaries
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -30,7 +31,7 @@ jobs:
GOARCH: ${{ matrix.goarch }}
run: |
go build -ldflags="-s -w" -o logfmt-${{ matrix.goos }}-${{ matrix.goarch }}-${{ github.ref_name }}

- name: Compress with UPX (Linux only)
if: matrix.goos == 'linux'
uses: crazy-max/ghaction-upx@v3
Expand All @@ -47,6 +48,7 @@ jobs:
retention-days: 1

create_release:
name: Create GitHub release from tag version
runs-on: ubuntu-latest
needs: build_release
permissions:
Expand All @@ -68,4 +70,4 @@ jobs:
name: "Release ${{ github.ref_name }}"
body: |
Automated release for tag ${{ github.ref_name }}.
files: release-artifacts/*/*
files: release-artifacts/*/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
58 changes: 41 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
---
version: "2"
linters:
enable:
- goimports
- stylecheck
- forbidigo
- lll
- prealloc
- predeclared
- staticcheck
- errcheck

run:
go: '1.22'
timeout: 30s

issues:
exclude-rules:
- linters:
- lll
source: "// nolint:lll"
- linters:
- unused
- deadcode
- varcheck
source: "// nolint:unused"
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- lll
source: // nolint:lll
- linters:
- staticcheck
source: // nolint:stylecheck
- linters:
- deadcode
- revive
- unused
- varcheck
source: // nolint:unused
- linters:
- staticcheck
text: 'SA1019:'
source: // ignore:deprecated
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
settings:
gci:
sections:
- standard
- default
- localmodule
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: setup lint test

setup: bin/golangci-lint
go mod download

bin:
mkdir bin

bin/golangci-lint: bin
GOBIN=$(PWD)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.0

lint: bin/golangci-lint
bin/golangci-lint fmt
go vet ./...
go mod tidy
bin/golangci-lint -c .golangci.yml run ./...

test:
go test -timeout=10s -race -cover ./...
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type rawConfig struct {
NoColor bool `long:"no-color" short:"n" description:"Disable color output"`
ForceColor bool `long:"force-color" short:"c" description:"Force color output, even when outputting to a pipe"`
NoTime bool `long:"no-time" short:"t" description:"Disable time output"`
KeepEmpty bool `long:"keep-empty" short:"k" description:"Keep lines with no field present selected by output or with all excluded"`
Raw bool `long:"raw" short:"r" description:"Output only selected fields values (comma separated) lcut like"`
All bool `long:"all" short:"A" description:"Output all field after the output fields effectivly making it ordered"`
KeepEmpty bool `long:"keep-empty" short:"k" description:"Keep lines with no field present selected by output or with all excluded"` // nolint:lll
Raw bool `long:"raw" short:"r" description:"Output only selected fields values (comma separated) lcut like"` // nolint:lll
All bool `long:"all" short:"A" description:"Output all field after the output fields effectivly making it ordered"` // nolint:lll
}

func Parse() (*Config, error) {
Expand Down
5 changes: 3 additions & 2 deletions parser/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"strings"
"time"

"github.com/TheEdgeOfRage/logfmt/config"
"github.com/fatih/color"
"github.com/go-logfmt/logfmt"

"github.com/TheEdgeOfRage/logfmt/config"
)

var (
Expand Down Expand Up @@ -155,7 +156,7 @@ func (r *Record) String(cfg *config.Config) string {
outFields := r.fieldOrder
if len(cfg.OutputFields) > 0 {
if cfg.All {
var reorderedFields []string = cfg.OutputFields
reorderedFields := cfg.OutputFields

for _, key := range r.fieldOrder {
if !slices.Contains(reorderedFields, key) {
Expand Down