From e0cde8002ac3b86ea11f7e1283abdecbb342f326 Mon Sep 17 00:00:00 2001 From: Ivan Fetch Date: Fri, 22 Jul 2022 04:56:50 -0600 Subject: [PATCH] Change module to github.com/ivanfetch/jkl, add GoReleaser and Makefile, update Go to 1.18 --- .gitignore | 5 +++++ .goreleaser.yml | 42 +++++++++++++++++++++++++++++++++++++++++ Makefile | 32 +++++++++++++++++++++++++++++++ archives_test.go | 3 ++- asdfconfig_test.go | 3 ++- cli.go | 9 +++++---- cmd/jkl/main.go | 3 ++- command_test.go | 3 ++- github_test.go | 3 ++- go.mod | 19 ++++++++++--------- go.sum | 1 + jkl.go | 15 ++++++++++----- jkl_integration_test.go | 2 +- jkl_test.go | 3 ++- version.go | 4 +--- 15 files changed, 119 insertions(+), 28 deletions(-) create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9436f9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +jkl +dist/ +stories.md +notes.md + diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..a7e7028 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,42 @@ +brews: +- name: jkl + # Do not update our tap repo if the git tag indicates prerelease. E.G. 1.0.0-rc1 + skip_upload: auto + goarm: 6 + tap: + owner: ivanfetch + name: homebrew-jkl + homepage: https://github.com/ivanfetch/jkl + description: JKL is a version manager for other command-line tools. It installs tools quickly with minimal input, and helps you switch versions of tools while you work. + caveats: You will need to add the jkl shims directory (default ~/.jkl/bin) to your PATH. + test: | + system "#{bin}/jkl version" +builds: +- ldflags: + - -X github.com/ivanfetch/jkl.Version={{.Version}} -X github.com/ivanfetch/jkl.GitCommit={{.Commit}} -s -w + env: + - CGO_ENABLED=0 + main: ./cmd/jkl + # goreleaser builds a matrix of the GOOS, GOArch, and GOARM listed below, + # minus those under `ignore`. + goarch: + - 386 + - amd64 + - arm + - arm64 + goos: + - linux + - darwin + # windows not yet tested + goarm: + - 6 + - 7 + ignore: + - goos: windows + goarch: arm64 +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c514745 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +BINARY=jkl +VERSION= $(shell (git describe --tags --dirty 2>/dev/null || echo dev) |cut -dv -f2) +GIT_COMMIT=$(shell git rev-parse HEAD) +LDFLAGS="-s -w -X github.com/ivanfetch/jkl.Version=$(VERSION) -X github.com/ivanfetch/jkl.GitCommit=$(GIT_COMMIT)" + +all: build + +.PHONY: fmt +fmt: + go fmt ./... + +.PHONY: vet +vet:go.sum + go vet ./... + +go.sum:go.mod + go get -t github.com/ivanfetch/jkl + +.PHONY: test +test:go.sum + go test ./... + +.PHONY: integrationtest +integrationtest:go.sum + go test -tags integration ./... + +.PHONY: binary +binary:go.sum + go build -ldflags $(LDFLAGS) -o $(BINARY) cmd/jkl/main.go + +.PHONY: build +build: fmt vet test binary diff --git a/archives_test.go b/archives_test.go index 910000e..2d4cd90 100644 --- a/archives_test.go +++ b/archives_test.go @@ -2,12 +2,13 @@ package jkl_test import ( "io/fs" - "jkl" "os" "path/filepath" "sort" "testing" + "github.com/ivanfetch/jkl" + "github.com/google/go-cmp/cmp" ) diff --git a/asdfconfig_test.go b/asdfconfig_test.go index b85ee2b..1701162 100644 --- a/asdfconfig_test.go +++ b/asdfconfig_test.go @@ -4,10 +4,11 @@ import ( "errors" "fmt" "io/fs" - "jkl" "os" "path/filepath" "testing" + + "github.com/ivanfetch/jkl" ) func TestFindASDFToolVersion(t *testing.T) { diff --git a/cli.go b/cli.go index 843f7d5..af86bda 100644 --- a/cli.go +++ b/cli.go @@ -40,11 +40,12 @@ func RunCLI(args []string, output, errOutput io.Writer) error { return err }, } + rootCmd.CompletionOptions.DisableDefaultCmd = true // Until completion behavior is tested rootCmd.PersistentFlags().BoolVarP(&debugFlagEnabled, "debug", "D", false, "Enable debug output (also enabled by setting the JKL_DEBUG environment variable to any value).") var versionCmd = &cobra.Command{ Use: "version", - Short: "Display the jkl version", + Short: "Display the jkl version and git commit", Long: "Display the jkl version and git commit", Aliases: []string{"ver", "v"}, Run: func(cmd *cobra.Command, args []string) { @@ -60,7 +61,7 @@ func RunCLI(args []string, output, errOutput io.Writer) error { If no version is specified, the latest version will be installed (not including pre-release versions). A partial major version will match the latest minor one. Available providers are: - github|gh - install a Github release`, + github|gh - install a Github release. The source is specified as /.`, Example: ` jkl install github:fairwindsops/rbac-lookup jkl install github:fairwindsops/rbac-lookup:0.9.0 jkl install github:fairwindsops/rbac-lookup:0.8`, @@ -93,10 +94,10 @@ jkl list rbac-lookup`, Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 1 { - j.displayInstalledVersionsOfTool(cmd.OutOrStdout(), args[0]) + err := j.displayInstalledVersionsOfTool(cmd.OutOrStdout(), args[0]) return err } - j.displayInstalledTools(cmd.OutOrStdout()) + err := j.displayInstalledTools(cmd.OutOrStdout()) return err }, } diff --git a/cmd/jkl/main.go b/cmd/jkl/main.go index 63dfc63..0334081 100644 --- a/cmd/jkl/main.go +++ b/cmd/jkl/main.go @@ -2,8 +2,9 @@ package main import ( "fmt" - "jkl" "os" + + "github.com/ivanfetch/jkl" ) func main() { diff --git a/command_test.go b/command_test.go index cdd6101..f8e998d 100644 --- a/command_test.go +++ b/command_test.go @@ -2,11 +2,12 @@ package jkl_test import ( "fmt" - "jkl" "os" "os/exec" "strings" "testing" + + "github.com/ivanfetch/jkl" ) // wrapRunCommand is a helper function that calls jkl.RunCommand() without diff --git a/github_test.go b/github_test.go index d9f3dc0..217e8d3 100644 --- a/github_test.go +++ b/github_test.go @@ -1,8 +1,9 @@ package jkl_test import ( - "jkl" "testing" + + "github.com/ivanfetch/jkl" ) func TestGithubMatchTagFromPartialVersion(t *testing.T) { diff --git a/go.mod b/go.mod index 13becad..ec3313a 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,18 @@ -module jkl +module github.com/ivanfetch/jkl replace github.com/ivanfetch/jkl => ./ -go 1.17 +go 1.18 -require github.com/spf13/pflag v1.0.5 +require ( + github.com/google/go-cmp v0.5.7 + github.com/h2non/filetype v1.1.3 + github.com/hashicorp/go-version v1.6.0 + github.com/mitchellh/go-homedir v1.1.0 + github.com/spf13/cobra v1.5.0 +) require ( - github.com/google/go-cmp v0.5.7 // indirect - github.com/h2non/filetype v1.1.3 // indirect - github.com/hashicorp/go-version v1.6.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect - github.com/ivanfetch/jkl v0.0.0-00010101000000-000000000000 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/spf13/cobra v1.5.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index 42fcba9..6effee3 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/jkl.go b/jkl.go index 6ea4975..b956fd9 100644 --- a/jkl.go +++ b/jkl.go @@ -132,13 +132,18 @@ func (j JKL) displayGettingStarted(output io.Writer) error { var numToolsPhrase string switch len(managedTools) { case 0: - numToolsPhrase = fmt.Sprintf("not yet managing any tools, to install your first tool using a Github release, run: %s install github:{user name}/{repository name}", callMeProgName) + numToolsPhrase = "not yet managing any tools" case 1: - numToolsPhrase = fmt.Sprintf("already managing 1 tool. Run %[1]s list to see a list of managed tools, or use %[1]s install to install more tools.", callMeProgName) + numToolsPhrase = "already managing one tool" default: - numToolsPhrase = fmt.Sprintf("already managing %d tools. Run %[2]s list to see a list of managed tools, or %[2]s install to install more tools.", len(managedTools), callMeProgName) - } - fmt.Fprintf(output, "%[1]s is %[2]s\n", callMeProgName, numToolsPhrase) + numToolsPhrase = fmt.Sprintf("already managing %d tools", len(managedTools)) + } + fmt.Fprintf(output, `%[1]s is %[2]s. +To install more tools, run: %[1]s install github:/ +To list jkl-managed tools, run: %[1]s list +To list installed versions of a tool, run: %[1]s list +For additional help, run: %[1]s help +`, callMeProgName, numToolsPhrase) return nil } diff --git a/jkl_integration_test.go b/jkl_integration_test.go index ca82a91..6f46502 100644 --- a/jkl_integration_test.go +++ b/jkl_integration_test.go @@ -4,8 +4,8 @@ package jkl_test import ( "fmt" + "github.com/ivanfetch/jkl" "io/fs" - "jkl" "os" "sort" "testing" diff --git a/jkl_test.go b/jkl_test.go index c0a1c0b..0b00e14 100644 --- a/jkl_test.go +++ b/jkl_test.go @@ -1,10 +1,11 @@ package jkl_test import ( - "jkl" "os" "testing" + "github.com/ivanfetch/jkl" + "github.com/google/go-cmp/cmp" ) diff --git a/version.go b/version.go index 73b288f..8fb2301 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,4 @@ package jkl -// This file is created by the release process. - -var Version string = "0.1.0" +var Version string = "dev" var GitCommit string = "unknown"