Skip to content

Commit

Permalink
bump version and remove spf13/viper
Browse files Browse the repository at this point in the history
  * go/1.19
  * spf13/cobra v1.6.1
  • Loading branch information
thazelart committed Dec 13, 2022
1 parent 72d8a06 commit e6bdd8c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 815 deletions.
44 changes: 30 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
BIN_NAME=golang-cli-template
IMAGE_NAME=thazelart/${BIN_NAME}
BIN_PATH=${GOPATH}/bin
GO_VERSION=1.17
GO_VERSION=1.19

help:
@echo 'Management commands for golang-cli-template:'
@echo
@echo 'Usage:'
@echo ' make get-deps Runs dep ensure, mostly used for ci.'
@echo ' make build Compile the project.'
@echo ' make docker-build Compile optimized for alpine linux.'
@echo ' make test-goreleaser Ensure the goreleaser config is valid.'
@echo
default: help

test-goreleaser:
## Test the goreleaser configuration locally.
test/goreleaser:
goreleaser --snapshot --skip-publish --rm-dist

get-deps:
## Run the unit tests.
test/go:
go test ./...

## Get this project dependencies.
local/deps:
go mod download

build:
## Build locally the go project.
go/build:
@echo "building ${BIN_NAME}"
@echo "GOPATH=${GOPATH}"
go generate ./...
go build -o ${BIN_PATH}/${BIN_NAME}

docker-build:
## Compile optimized for alpine linux.
docker/build:
@echo "building image ${IMAGE_NAME}"
docker build --build-arg GO_VERSION=${GO_VERSION} -t $(IMAGE_NAME):latest .

## Print his help screen
help:
@printf "Available targets:\n\n"
@awk '/^[a-zA-Z\-\_0-9%:\\]+/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-15s\x1b[0m %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
@printf "\n"
34 changes: 3 additions & 31 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ limitations under the License.
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string
Expand All @@ -47,39 +45,13 @@ func Execute() {
}

func init() {
cobra.OnInitialize(initConfig)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.golang-cli-template.yaml)")
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.test.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)

// Search config in home directory with name ".golang-cli-template" (without extension).
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".golang-cli-template")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
22 changes: 4 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
module github.com/thazelart/golang-cli-template

go 1.17
go 1.19

require (
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.10.1
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e6bdd8c

Please sign in to comment.