diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 537e933..3041cf0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,4 +23,4 @@ jobs: just sysinfo - name: Run Go Test run: | - just init tidy lint test + just init tidy lint tests diff --git a/.github/workflows/scripts/golangci.yaml b/.github/workflows/scripts/golangci.yaml index dfa19b8..432cc83 100644 --- a/.github/workflows/scripts/golangci.yaml +++ b/.github/workflows/scripts/golangci.yaml @@ -1,46 +1,46 @@ -run: - timeout: 5m +version: "2" linters: enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - copyloopvar - - dogsled - - dupword - - durationcheck - - errcheck - - errname - - errorlint - - exhaustive - - gochecknoinits - - gocritic - - gofmt - - gosimple - - govet - - ineffassign - - makezero - - misspell - - musttag - - nilnil - - noctx - - paralleltest - - perfsprint - - prealloc - - predeclared - - reassign - - revive - - rowserrcheck - - staticcheck - - sqlclosecheck - - tagalign - - tenv - - unused - - whitespace - -linters-settings: - paralleltest: - ignore-missing-subtests: true - exhaustive: - default-signifies-exhaustive: true + - asasalint + - asciicheck + - bidichk + - bodyclose + - copyloopvar + - dogsled + - dupword + - durationcheck + - errname + - errorlint + - exhaustive + - gochecknoinits + - gocritic + - makezero + - misspell + - musttag + - nilnil + - noctx + - paralleltest + - perfsprint + - prealloc + - predeclared + - reassign + - revive + - rowserrcheck + - sqlclosecheck + - tagalign + - usetesting + - whitespace + settings: + exhaustive: + default-signifies-exhaustive: true + paralleltest: + ignore-missing-subtests: true + exclusions: + generated: lax + presets: + - comments +formatters: + enable: + - gofmt + exclusions: + generated: lax diff --git a/Justfile b/Justfile index bb26c26..2393990 100644 --- a/Justfile +++ b/Justfile @@ -15,7 +15,7 @@ tidy: # run tests across source tree [group('build')] -test: +tests: go test -v -race -count=1 ./... # apply go vet command on source tree @@ -31,7 +31,7 @@ lint: vet # locally install build dependencies [group('build')] init: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0 # show host system information [group('build')] diff --git a/commands.go b/commands.go index 3ed94cb..d9485fd 100644 --- a/commands.go +++ b/commands.go @@ -185,6 +185,11 @@ func (c *Component) run(output io.Writer) *result { func (c *Component) processFlags() bool { arg := c.args.Peek() + if arg == "--" { + c.args.Pop() + return false + } + switch { case strings.HasPrefix(arg, "--"): c.consumeFlag() @@ -247,11 +252,11 @@ func (c *Component) consumeBoolFlag(identity string) { } next := c.args.Peek() - switch { - case next == "true": + switch next { + case "true": c.vals.bools[identity] = append(c.vals.bools[identity], true) _ = c.args.Pop() - case next == "false": + case "false": c.vals.bools[identity] = append(c.vals.bools[identity], false) _ = c.args.Pop() default: diff --git a/commands_test.go b/commands_test.go index e314186..9d3cddb 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1994,6 +1994,16 @@ func TestArguments_top(t *testing.T) { args: []string{"one", "two", "three"}, expText: "hello [one two three]", }, + { + name: "terminator", + args: []string{"--", "-1"}, + expText: "hello [-1]", + }, + { + name: "terminator multiple", + args: []string{"--", "-1", "-2"}, + expText: "hello [-1 -2]", + }, } for _, tc := range cases { @@ -2046,6 +2056,11 @@ func TestArguments_child(t *testing.T) { args: []string{"child", "one", "two", "three"}, expText: "hi [one two three]", }, + { + name: "terminator", + args: []string{"child", "--", "-1"}, + expText: "hi [-1]", + }, } for _, tc := range cases { @@ -2072,3 +2087,30 @@ func TestArguments_child(t *testing.T) { }) } } + +func TestRun_flagTerminator(t *testing.T) { + t.Parallel() + + var output string + + config := &Configuration{ + Arguments: []string{"--name", "bob", "--", "-1"}, + Top: &Component{ + Flags: Flags{ + { + Type: StringFlag, + Long: "name", + }, + }, + Function: func(c *Component) Code { + output = fmt.Sprintf("%s %v", c.GetString("name"), c.Arguments()) + return Success + }, + }, + } + + c := New(config) + result := c.Run() + must.Eq(t, "bob [-1]", output) + must.Eq(t, Success, result) +} diff --git a/go.mod b/go.mod index 498a73b..d4c8e22 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module cattlecloud.net/go/babycli -go 1.23 +go 1.27 require ( cattlecloud.net/go/stacks v1.1.2