Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gvm use -n/--no-install option #35

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cmd/gvm/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ import (
"fmt"
"path/filepath"

kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/andrewkroh/gvm"
"github.com/andrewkroh/gvm/cmd/gvm/internal/shellfmt"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type useCmd struct {
version string
build bool
format string
build,
noInstall bool
format string
}

func useCommand(cmd *kingpin.CmdClause) func(*gvm.Manager) error {
ctx := &useCmd{}

cmd.Arg("version", "Go version to install (e.g. 1.10.3).").StringVar(&ctx.version)
cmd.Flag("build", "Build go version from source").Short('b').BoolVar(&ctx.build)
cmd.Flag("no-install", "Don't install if missing").Short('n').BoolVar(&ctx.noInstall)
cmd.Flag("format", "Format to use for the shell commands. Options: bash, batch, powershell").
Short('f').
Default(shellfmt.DefaultFormat()).
Expand All @@ -46,6 +49,15 @@ func (cmd *useCmd) Run(manager *gvm.Manager) error {
var goroot string
if cmd.build {
goroot, err = manager.Build(ver)
} else if cmd.noInstall {
has, err := manager.HasVersion(ver)
if err != nil {
return err
}
if !has {
return fmt.Errorf("version %s not installed and --no-install enabled", ver)
}
goroot = manager.VersionGoROOT(ver)
} else {
goroot, err = manager.Install(ver)
}
Expand Down