From 6588dddbe2e05dbd24ae9eae29b4b0cf50a83e54 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 03:15:52 +0000 Subject: [PATCH 1/8] Fix typos --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c273c37..9ba2526 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ It can also apply the license you specify to your application. With the introduction of Go modules, the Cobra generator has been simplified to take advantage of modules. The Cobra generator works from within a Go module. -#### Initalizing a module +#### Initializing a module __If you already have a module, skip this step.__ @@ -39,7 +39,7 @@ cd myapp go mod init github.com/spf13/myapp ``` -#### Initalizing a Cobra CLI application +#### Initializing a Cobra CLI application From within a Go module run `cobra-cli init`. This will create a new barebones project for you to edit. @@ -95,13 +95,13 @@ You'll notice that this final command has a `-p` flag. This is used to assign a parent command to the newly added command. In this case, we want to assign the "create" command to the "config" command. All commands have a default parent of rootCmd if not specified. -By default `cobra-cli` will append `Cmd` to the name provided and uses this name for the internal variable name. When specifying a parent, be sure to match the variable name used in the code. +By default `cobra-cli` will append `Cmd` to the name provided and use this name for the internal variable name. When specifying a parent, be sure to match the variable name used in the code. *Note: Use camelCase (not snake_case/kebab-case) for command names. Otherwise, you will encounter errors. For example, `cobra-cli add add-user` is incorrect, but `cobra-cli add addUser` is valid.* -Once you have run these three commands you would have an app structure similar to +Once you have run these three commands you will have an app structure similar to the following: ``` From ee428039aeea807117dfe95a8d31df16178ef967 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:02:17 +0000 Subject: [PATCH 2/8] Fix CI --- .github/workflows/test.yml | 109 +++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8821146..25d6a12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,3 +1,4 @@ +--- name: Test on: @@ -16,7 +17,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: '^1.22' - uses: actions/checkout@v3.1.0 @@ -30,39 +31,43 @@ jobs: fail-fast: false matrix: platform: - - ubuntu - - macOS + - ubuntu + - macOS go: - - 14 - - 15 - - 16 - - 17 + - 17 + - 18 + - 19 + - 20 + - 21 + - 22 + - 23 + - 24 name: '${{ matrix.platform }} | 1.${{ matrix.go }}.x' runs-on: ${{ matrix.platform }}-latest steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.${{ matrix.go }}.x + - uses: actions/setup-go@v2 + with: + go-version: 1.${{ matrix.go }}.x - - uses: actions/checkout@v3.1.0 + - uses: actions/checkout@v3.1.0 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-1.${{ matrix.go }}.x-${{ hashFiles('**/go.sum') }} - restore-keys: ${{ runner.os }}-1.${{ matrix.go }}.x- + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-1.${{ matrix.go }}.x-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-1.${{ matrix.go }}.x- - - run: | - export GOBIN=$HOME/go/bin - case "${{ matrix.go }}" in - 16|17) _version='@latest';; - *) _version='';; - esac - go install github.com/kyoh86/richgo"${_version}" - go install github.com/mitchellh/gox"${_version}" + - run: | + export GOBIN=$HOME/go/bin + case "${{ matrix.go }}" in + 16|17) _version='@latest';; + *) _version='';; + esac + go install github.com/kyoh86/richgo"${_version}" + go install github.com/mitchellh/gox"${_version}" - - run: PATH=$HOME/go/bin/:$PATH make test build + - run: PATH=$HOME/go/bin/:$PATH make test build test-win: name: MINGW64 @@ -72,30 +77,30 @@ jobs: runs-on: windows-latest steps: - - shell: bash - run: git config --global core.autocrlf input - - - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - update: true - install: > - git - make - unzip - mingw-w64-x86_64-go - - - uses: actions/checkout@v3.1.0 - - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }} - restore-keys: ${{ runner.os }}-${{ matrix.go }}- - - - run: | - export GOBIN=$HOME/go/bin - go install github.com/kyoh86/richgo@latest - go install github.com/mitchellh/gox@latest - - - run: PATH=$HOME/go/bin:$PATH make test build + - shell: bash + run: git config --global core.autocrlf input + + - uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: > + git + make + unzip + mingw-w64-x86_64-go + + - uses: actions/checkout@v3.1.0 + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-${{ matrix.go }}- + + - run: | + export GOBIN=$HOME/go/bin + go install github.com/kyoh86/richgo@latest + go install github.com/mitchellh/gox@latest + + - run: PATH=$HOME/go/bin:$PATH make test build From 2694b5cdd2111de2b06aa7e7e1f63e6cb38b8e19 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:19:42 +0000 Subject: [PATCH 3/8] Update copyright --- cmd/testdata/main.go.golden | 2 +- cmd/testdata/root.go.golden | 2 +- cmd/testdata/test.go.golden | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/testdata/main.go.golden b/cmd/testdata/main.go.golden index 714c24f..575e9b7 100644 --- a/cmd/testdata/main.go.golden +++ b/cmd/testdata/main.go.golden @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2025 NAME HERE Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cmd/testdata/root.go.golden b/cmd/testdata/root.go.golden index f23bb6d..4a1b90f 100644 --- a/cmd/testdata/root.go.golden +++ b/cmd/testdata/root.go.golden @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2025 NAME HERE Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cmd/testdata/test.go.golden b/cmd/testdata/test.go.golden index 1fb39e2..d5071d8 100644 --- a/cmd/testdata/test.go.golden +++ b/cmd/testdata/test.go.golden @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2025 NAME HERE Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 5e86c23815be91b4eb0eb9175d4ca8c73935209a Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:23:57 +0000 Subject: [PATCH 4/8] Fix CI --- .github/workflows/test.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25d6a12..ac40ae8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,12 +60,8 @@ jobs: - run: | export GOBIN=$HOME/go/bin - case "${{ matrix.go }}" in - 16|17) _version='@latest';; - *) _version='';; - esac - go install github.com/kyoh86/richgo"${_version}" - go install github.com/mitchellh/gox"${_version}" + go install github.com/kyoh86/richgo@latest + go install github.com/mitchellh/gox@latest - run: PATH=$HOME/go/bin/:$PATH make test build From 0b40e61d49de32c701489c96fbeebab0544bc298 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:28:25 +0000 Subject: [PATCH 5/8] Update `actions/checkout`, `actions/setup-go@v5` and `golangci/golangci-lint-action` versions --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac40ae8..51d433d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,13 +15,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v5 with: go-version: '^1.22' - - uses: actions/checkout@v3.1.0 + - uses: actions/checkout@v4 - - uses: golangci/golangci-lint-action@v2 + - uses: golangci/golangci-lint-action@v4.0.0 with: version: latest args: --verbose From f1baa73836c0b209ceaeb677399f4bfd0255574d Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:35:21 +0000 Subject: [PATCH 6/8] Update .golangci.yml (taken from the main cobra repo). --- .golangci.yml | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 0d6e617..2c8f480 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,17 @@ +# Copyright 2013-2023 The Cobra Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + run: deadline: 5m @@ -5,44 +19,39 @@ linters: disable-all: true enable: #- bodyclose - - deadcode + # - deadcode ! deprecated since v1.49.0; replaced by 'unused' #- depguard #- dogsled #- dupl - errcheck #- exhaustive #- funlen - - gas #- gochecknoinits - goconst - #- gocritic + - gocritic #- gocyclo - #- gofmt + - gofmt - goimports - - golint #- gomnd #- goprintffuncname - #- gosec - #- gosimple + - gosec + - gosimple - govet - ineffassign - - interfacer #- lll - - maligned - - megacheck - #- misspell + - misspell #- nakedret #- noctx - #- nolintlint + - nolintlint #- rowserrcheck #- scopelint - #- staticcheck - - structcheck - #- stylecheck + - staticcheck + #- structcheck ! deprecated since v1.49.0; replaced by 'unused' + - stylecheck #- typecheck - unconvert #- unparam - #- unused - - varcheck + - unused + # - varcheck ! deprecated since v1.49.0; replaced by 'unused' #- whitespace fast: false From 471d6d2191c4cb963e7c5a79e37b4263e0ef1da8 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:36:15 +0000 Subject: [PATCH 7/8] Update .golangci.yml (taken from the main cobra repo). --- .golangci.yml | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2c8f480..c639cb0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,4 @@ -# Copyright 2013-2023 The Cobra Authors +# Copyright 2013-2025 The Cobra Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,46 +12,47 @@ # See the License for the specific language governing permissions and # limitations under the License. +--- run: deadline: 5m linters: disable-all: true enable: - #- bodyclose + # - bodyclose # - deadcode ! deprecated since v1.49.0; replaced by 'unused' - #- depguard - #- dogsled - #- dupl + # - depguard + # - dogsled + # - dupl - errcheck - #- exhaustive - #- funlen - #- gochecknoinits + # - exhaustive + # - funlen + # - gochecknoinits - goconst - gocritic - #- gocyclo + # - gocyclo - gofmt - goimports - #- gomnd - #- goprintffuncname + # - gomnd + # - goprintffuncname - gosec - gosimple - govet - ineffassign - #- lll + # - lll - misspell - #- nakedret - #- noctx + # - nakedret + # - noctx - nolintlint - #- rowserrcheck - #- scopelint + # - rowserrcheck + # - scopelint - staticcheck - #- structcheck ! deprecated since v1.49.0; replaced by 'unused' + # - structcheck ! deprecated since v1.49.0; replaced by 'unused' - stylecheck - #- typecheck + # - typecheck - unconvert - #- unparam + # - unparam - unused # - varcheck ! deprecated since v1.49.0; replaced by 'unused' - #- whitespace + # - whitespace fast: false From 02ab7c4ebc5056e0d6a46bdb801545a1581791d2 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 24 Feb 2025 14:39:19 +0000 Subject: [PATCH 8/8] Fix: Error: sloppyLen: len(goExecutable) <= 0 can be len(goExecutable) == 0 (gocritic) Error: wrapperFunc: use bytes.ReplaceAll method in `bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1)` (gocritic) --- cmd/golden_test.go | 2 +- cmd/helpers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/golden_test.go b/cmd/golden_test.go index 832ea53..ec9d254 100644 --- a/cmd/golden_test.go +++ b/cmd/golden_test.go @@ -18,7 +18,7 @@ func init() { // ensureLF converts any \r\n to \n func ensureLF(content []byte) []byte { - return bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1) + return bytes.ReplaceAll(content, []byte("\r\n"), []byte("\n")) } // compareFiles compares the content of files with pathA and pathB. diff --git a/cmd/helpers.go b/cmd/helpers.go index 6a8047e..3afb943 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -36,7 +36,7 @@ func init() { // possible. goExecutable := os.Getenv("COBRA_GO_EXECUTABLE") - if len(goExecutable) <= 0 { + if len(goExecutable) == 0 { goExecutable = "go" }