Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wreulicke authored Jul 5, 2024
0 parents commit 9a558f9
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release
on:
push:
branches:
- "!*"
tags:
- "v*"

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
name: GoReleaser
steps:
- uses: actions/checkout@master
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22.5'
- name: Run go mod download
run: go mod download
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: "v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test
on:
push:
branches:
- master
pull_request:

permissions:
contents: read
pull-requests: write

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22.5'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.0
- uses: actions/checkout@v4
- name: test
run: make test
- uses: k1LoW/octocov-action@v1
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

build
35 changes: 35 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
linters:
enable-all: true
disable:
- varnamelen
- testpackage
- nonamedreturns
- nlreturn
- ireturn
- mnd
- gomnd
- exhaustruct
- goconst
- depguard
- wsl
- lll
- cyclop
- gocognit
- gocyclo
- maintidx
- execinquery
- gochecknoglobals

linters-settings:
revive:
rules:
# うるさいので止める
- name: unused-parameter
disabled: true

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- forcetypeassert
30 changes: 30 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
builds:
- main: ./cmd/go-cli-template
binary: go-cli-template
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ldflags:
- -s -w
checksum:
name_template: checksums.txt
archives:
- format: binary
snapshot:
name_template: master
changelog:
sort: asc
filters:
exclude:
- "Merge pull request"
- "Merge branch"
release:
github:
owner: wreulicke
name: go-cli-template
23 changes: 23 additions & 0 deletions .octocov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
comment:
codeToTestRatio:
code:
- '**/*.go'
- '!**/*_test.go'
test:
- '**/*_test.go'
coverage:
paths:
- build/coverage.out
summary:
if: true
body:
if: is_pull_request
testExecutionTime:
if: true
diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
report:
if: is_default_branch
datastores:
- artifact://${GITHUB_REPOSITORY}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 wreulicke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

.PHONY: test
test:
mkdir -p build
go test ./... -v -race -coverprofile=build/coverage.out
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# go-cli-template

This is my repository template for cli tool in go.

## Installation

```
```

## Usage

```bash
go-cli-template

Usage:
go-cli-template [flags]
go-cli-template [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version show version

Flags:
-h, --help help for go-cli-template

Use "go-cli-template [command] --help" for more information about a command.
```

## License

MIT License
62 changes: 62 additions & 0 deletions cmd/go-cli-template/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"debug/buildinfo"
"fmt"
"log"
"os"

"github.com/spf13/cobra"
)

func mainInternal() error {
//nolint:wrapcheck
return NewApp().Execute()
}

func main() {
if err := mainInternal(); err != nil {
log.Fatal(err)
}
}

func NewApp() *cobra.Command {
c := cobra.Command{
Use: "go-cli-template",
Short: "go-cli-template",
RunE: func(cmd *cobra.Command, args []string) error {
// nop
return nil
},
}

c.AddCommand(
NewVersionCommand(),
)
return &c
}

func NewVersionCommand() *cobra.Command {
var detail bool
c := &cobra.Command{
Use: "version",
Short: "show version",
RunE: func(cmd *cobra.Command, args []string) error {
w := cmd.OutOrStdout()
info, err := buildinfo.ReadFile(os.Args[0])
if err != nil {
return fmt.Errorf("cannot read buildinfo: %w", err)
}

fmt.Fprintf(w, "go version: %s", info.GoVersion)
fmt.Fprintf(w, "module version: %s", info.Main.Version)
if detail {
fmt.Fprintln(w)
fmt.Fprintln(w, info)
}
return nil
},
}
c.Flags().BoolVarP(&detail, "detail", "d", false, "show details")
return c
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/wreulicke/go-cli-template

go 1.22

require github.com/spf13/cobra v1.8.1

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 9a558f9

Please sign in to comment.