Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
drewgonzales360 committed Apr 3, 2024
1 parent bd6ccfc commit c0aea61
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 84 deletions.
39 changes: 17 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# goenv

![github workflow](https://github.com/drewgonzales360/goenv/actions/workflows/github-actions.yml/badge.svg)
[![Go Reference](https://pkg.go.dev/badge/pkg.go.dev/drewgonzales360/goenv.svg)](https://pkg.go.dev/github.com/drewgonzales360/goenv)

`goenv` is an small, simple binary that executes the [install instructions](https://go.dev/doc/install) on the Go website and manages several Go versions. `goenv` downloads and extracts go to `/usr/local/goenv/<VERSION>` and adds a symlink from `/usr/local/go -> /usr/local/goenv/<VERSION>` (by default). It was loosely inspired by [Dave Cheney's blog post](https://dave.cheney.net/2014/04/20/how-to-install-multiple-versions-of-go).

Expand All @@ -9,38 +10,32 @@
Calling `goenv` without any arguments will print out a helpful block of text, but here are a few useful examples. Note that installing 1.14 will install 1.14, even if 1.14.5 is the latest patch version.

```bash
$ goenv
NAME:
goenv - Manages multiple Go versions. See https://go.dev/dl for available versions.
# Helpful list of commands
❯ goenv
Usage:
[command]

USAGE:
goenv <command> [version]
Available Commands:
config Print out the current config
install Install a Go version. Usually in the form 1.18, 1.9, 1.17.8.
list List all installed available Go versions.
uninstall Uninstall a Go version.
use Switch the current Go version to use whichever version in specified and installed.

VERSION:
v0.3.0+7a5bcdd
Flags:
-h, --help help for this command
-v, --version version for this command

AUTHOR:
Drew Gonzales <github.com/drewgonzales360>

COMMANDS:
install, i Install a Go version. Usually in the form 1.18, 1.9, 1.17.8.
uninstall, rm Uninstall a Go version
use, u Use a Go version
list, ls, l List available Go versions
config, c Prints the current config.

GLOBAL OPTIONS:
--help, -h show help (default: false)
--version, -v print the version (default: false)
Use " [command] --help" for more information about a command.

# Install and use a go version
$ goenv i 1.17
$ goenv install 1.17
✅ Downloaded and validated Go 1.17
✅ Extracted package
😎 Using go version go1.17 darwin/amd64

# Use an installed version. This will fail if you don't have it installed.
$ goenv u 1.19
$ goenv use 1.19
😎 Using go version go1.19 darwin/amd64

# Removes an installed version and switches to another one if available
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package cmd

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package cmd

import (
"bytes"
"fmt"
Expand Down Expand Up @@ -44,7 +44,7 @@ const (
configSetByEnv = "\t(set by environment variable)\n"
)

func ConfigCommand(cmd *cobra.Command, _ []string) {
func ConfigCommand(cmd *cobra.Command, _ []string) {
config := ReadConfig()
fmt.Print(config)
warnOnMissingPath(config)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/helpers.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package cmd

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package cmd

import (
"fmt"
"os"
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package cmd

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package cmd

import (
"fmt"
"path"
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package cmd

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package cmd

import (
"os"

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/uninstall.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package cmd

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package cmd

import (
"fmt"
"os"
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/use.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package cmd

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package cmd

import (
"fmt"
"os"
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/discover.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"encoding/json"
"fmt"
Expand Down Expand Up @@ -137,7 +137,7 @@ func toLooseGoVersion(v *semver.Version) string {
// If we have 1.18, we'd parse the version to 1.18.0, but the URL doesn't
// actually inclued the last .0. Starting in Go 1.21, we leave the .0 at the
// end.
if v.Patch() == 0 && v.LessThan(semver.MustParse("1.21.0")){
if v.Patch() == 0 && v.LessThan(semver.MustParse("1.21.0")) {
urlVersion = strings.TrimSuffix(urlVersion, ".0")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/discover_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"testing"

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/download.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"archive/tar"
"compress/gzip"
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/download_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg_test

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg_test

import (
"path"
"testing"
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/latest.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"bytes"
"context"
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"os"

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"os"
"path"
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/versions.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package pkg

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package pkg

import (
"fmt"
"sort"
Expand Down
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package main

// ///////////////////////////////////////////////////////////////////////
// Copyright 2024 Drew Gonzales
//
Expand All @@ -13,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ///////////////////////////////////////////////////////////////////////
package main

import (
"fmt"
"os"
Expand All @@ -39,7 +39,7 @@ func main() {
installCmd := &cobra.Command{
Use: "install",
Short: "Install a Go version. Usually in the form 1.18, 1.9, 1.17.8.",
Example: fmt.Sprintf("ex: %s install 1.19.1", appName),
Example: fmt.Sprintf(" ex: %s install 1.19.1", appName),
Aliases: []string{"i"},
RunE: cmd.InstallCommand,
Args: cmd.ValidateVersionArg,
Expand All @@ -49,7 +49,7 @@ func main() {
uninstallCmd := &cobra.Command{
Use: "uninstall",
Short: "Uninstall a Go version.",
Example: fmt.Sprintf("ex: %s uninstall 1.17", appName),
Example: fmt.Sprintf(" ex: %s uninstall 1.17", appName),
Aliases: []string{"rm"},
RunE: cmd.UninstallCommand,
Args: cmd.ValidateVersionArg,
Expand All @@ -59,7 +59,7 @@ func main() {
useCmd := &cobra.Command{
Use: "use",
Short: "Switch the current Go version to use whichever version in specified and installed.",
Example: fmt.Sprintf("ex: %s use 1.18", appName),
Example: fmt.Sprintf(" ex: %s use 1.18", appName),
Aliases: []string{"u"},
RunE: cmd.UseCommand,
Args: cmd.ValidateVersionArg,
Expand Down Expand Up @@ -88,9 +88,10 @@ func main() {

rootCmd := &cobra.Command{Version: Semver}
rootCmd.AddCommand(installCmd, uninstallCmd, useCmd, listCmd, configCmd)
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})

err := rootCmd.Execute()
if err != nil {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
6 changes: 3 additions & 3 deletions scripts/goenv-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ function test-command() {
fi
}

test-command "goenv install 1.18" "1b3aab6f0142d34d991ce0cc8ec3e591"
test-command "goenv install 1.18" "5189677c7fdba8d0e1f26ae57898566a"
test-command "sudo goenv install 1.18" "d38b90a90390b3756e1992a34618c7a4"
test-command "sudo goenv use 1.17.8" "628121bce55eca109aa4aae8f6ffa010"
test-command "sudo goenv use 1.17.8" "3e1880a51ac2fd015223db2084751dff"
test-command "sudo goenv install 1.17.8" "5119f6686cf0257ff262145d61db303a"
test-command "sudo goenv use 1.18" "d38b90a90390b3756e1992a34618c7a4"
test-command "goenv use 1.18" "1d7e424e4c311c2f67bf53c538367bb3"
test-command "goenv use 1.18" "283676a4365f1a4252d867ceab29ee5e"
test-command "sudo goenv install 1.19.1" "58339c01166fbb80bfd20e08b801939e"
test-command "sudo goenv install 1.18.1" "cb2fd36806cd2ed911e63bbd9cdbd385"
test-command "sudo goenv rm 1.18" "48bacb95c998567dcb71c4c8d80f0580"
Expand Down
Loading

0 comments on commit c0aea61

Please sign in to comment.