Skip to content

Commit

Permalink
Change module to github.com/ivanfetch/jkl, add GoReleaser and Makefil…
Browse files Browse the repository at this point in the history
…e, update Go to 1.18
  • Loading branch information
ivanfetch committed Jul 22, 2022
1 parent c523a04 commit e0cde80
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jkl
dist/
stories.md
notes.md

42 changes: 42 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:'
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion archives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
3 changes: 2 additions & 1 deletion asdfconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"errors"
"fmt"
"io/fs"
"jkl"
"os"
"path/filepath"
"testing"

"github.com/ivanfetch/jkl"
)

func TestFindASDFToolVersion(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 <Github user>/<Github repository>.`,
Example: ` jkl install github:fairwindsops/rbac-lookup
jkl install github:fairwindsops/rbac-lookup:0.9.0
jkl install github:fairwindsops/rbac-lookup:0.8`,
Expand Down Expand Up @@ -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
},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/jkl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
"jkl"
"os"

"github.com/ivanfetch/jkl"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion github_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package jkl_test

import (
"jkl"
"testing"

"github.com/ivanfetch/jkl"
)

func TestGithubMatchTagFromPartialVersion(t *testing.T) {
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
15 changes: 10 additions & 5 deletions jkl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:<Github user>/<Github repository>
To list jkl-managed tools, run: %[1]s list
To list installed versions of a tool, run: %[1]s list <ToolName>
For additional help, run: %[1]s help
`, callMeProgName, numToolsPhrase)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion jkl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package jkl_test

import (
"fmt"
"github.com/ivanfetch/jkl"
"io/fs"
"jkl"
"os"
"sort"
"testing"
Expand Down
3 changes: 2 additions & 1 deletion jkl_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jkl_test

import (
"jkl"
"os"
"testing"

"github.com/ivanfetch/jkl"

"github.com/google/go-cmp/cmp"
)

Expand Down
4 changes: 1 addition & 3 deletions version.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit e0cde80

Please sign in to comment.