diff --git a/client/client.go b/client/client.go index c475ad5..00cc720 100644 --- a/client/client.go +++ b/client/client.go @@ -148,10 +148,9 @@ func (s *Shed) writeLockfile() error { // Install does not modify any state, therefore, if you wish to abort the install simply // discard the returned InstallSet. // -// If a tool name is provided with a version and the same tool already exists in the -// lockfile with a different version, then Install will return an error, unless allowUpdates -// is set in which case the given tool version will overwrite the one in the lockfile. -func (s *Shed) Install(allowUpdates bool, toolNames ...string) (*InstallSet, error) { +// All tool names provided must be full import paths, not binary names. +// If a tool name is invalid, Install will return an error. +func (s *Shed) Install(toolNames ...string) (*InstallSet, error) { // Collect all the tools that need to be installed. // Merge the given tools with what exists in the lockfile. seenTools := make(map[string]bool) @@ -166,20 +165,6 @@ func (s *Shed) Install(allowUpdates bool, toolNames ...string) (*InstallSet, err errs = append(errs, errors.WithMessagef(err, "invalid tool name %s", toolName)) continue } - - existing, err := s.lf.GetTool(toolName) - if errors.Is(err, lockfile.ErrIncorrectVersion) { - if !allowUpdates { - err := errors.Errorf("trying to install %s, but %s is in the lockfile", t, existing.Version) - errs = append(errs, err) - continue - } - } else if err != nil && !errors.Is(err, lockfile.ErrNotFound) { - // Shouldn't happen, but handle just to be safe - errs = append(errs, errors.WithMessagef(err, "failed to check if tool exists in lockfile: %s", t)) - continue - } - seenTools[t.ImportPath] = true tools = append(tools, t) } diff --git a/client/client_test.go b/client/client_test.go index f66ef60..de1204f 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -163,7 +163,6 @@ func TestInstall(t *testing.T) { name string lockfileTools []tool.Tool installTools []string - allowUpdates bool wantLen int wantTools []tool.Tool }{ @@ -175,8 +174,7 @@ func TestInstall(t *testing.T) { "github.com/golangci/golangci-lint/cmd/golangci-lint", "github.com/Shopify/ejson/cmd/ejson", }, - allowUpdates: false, - wantLen: 3, + wantLen: 3, wantTools: []tool.Tool{ {ImportPath: "github.com/cszatmary/go-fish", Version: "v0.1.0"}, {ImportPath: "github.com/golangci/golangci-lint/cmd/golangci-lint", Version: "v1.33.0"}, @@ -191,8 +189,7 @@ func TestInstall(t *testing.T) { "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.28.3", "github.com/Shopify/ejson/cmd/ejson@v1.1.0", }, - allowUpdates: false, - wantLen: 3, + wantLen: 3, wantTools: []tool.Tool{ {ImportPath: "github.com/cszatmary/go-fish", Version: "v0.0.0-20201203230243-22d10c9b658d"}, {ImportPath: "github.com/golangci/golangci-lint/cmd/golangci-lint", Version: "v1.28.3"}, @@ -207,7 +204,6 @@ func TestInstall(t *testing.T) { {ImportPath: "github.com/Shopify/ejson/cmd/ejson", Version: "v1.1.0"}, }, installTools: nil, - allowUpdates: false, wantLen: 3, wantTools: []tool.Tool{ {ImportPath: "github.com/cszatmary/go-fish", Version: "v0.1.0"}, @@ -225,8 +221,7 @@ func TestInstall(t *testing.T) { installTools: []string{ "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.33.0", }, - allowUpdates: true, - wantLen: 3, + wantLen: 3, wantTools: []tool.Tool{ {ImportPath: "github.com/cszatmary/go-fish", Version: "v0.1.0"}, {ImportPath: "github.com/golangci/golangci-lint/cmd/golangci-lint", Version: "v1.33.0"}, @@ -257,7 +252,7 @@ func TestInstall(t *testing.T) { t.Fatalf("failed to create shed client %v", err) } - installSet, err := s.Install(tt.allowUpdates, tt.installTools...) + installSet, err := s.Install(tt.installTools...) if err != nil { t.Errorf("want nil error, got %v", err) } @@ -308,7 +303,6 @@ func TestInstallError(t *testing.T) { } _, err = s.Install( - false, "github.com/cszatmary/go-fish", "golangci-lint", "github.com/Shopify/ejson/cmd/ejson@v1.2.2", @@ -317,7 +311,7 @@ func TestInstallError(t *testing.T) { if !ok { t.Errorf("want error to be lockfile.ErrorList, got %s: %T", err, err) } - wantLen := 2 + wantLen := 1 if len(errList) != wantLen { t.Errorf("got %d errors, want %d", len(errList), wantLen) } diff --git a/cmd/install.go b/cmd/install.go index 982bba7..0759abb 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -12,12 +12,6 @@ import ( "github.com/spf13/cobra" ) -type installOptions struct { - allowUpdates bool -} - -var installOpts installOptions - var installCmd = &cobra.Command{ Use: "install [tools...]", Args: cobra.ArbitraryArgs, @@ -33,10 +27,6 @@ an '@', just like with 'go get' in module-aware mode. If no version is provided, If no tools are provided, then shed will simply install all tools in the lockfile. -By default shed prevents installing a tool if a different version of the same tool already exists in the shed.lock file. -If you wish to update the tool, the '-u' or '--update' flag can be used. This will cause shed to install the new version -of the tool specified and update the shed.lock file. - Examples: Install the latest version of a tool: @@ -54,7 +44,7 @@ Install all tools specified in shed.lock: logger := newLogger() setwd(logger) shed := mustShed(client.WithLogger(logger)) - installSet, err := shed.Install(installOpts.allowUpdates, args...) + installSet, err := shed.Install(args...) if err != nil { fatal.ExitErrf(err, "Failed to determine list of tools to install") } @@ -101,6 +91,5 @@ Install all tools specified in shed.lock: } func init() { - installCmd.Flags().BoolVarP(&installOpts.allowUpdates, "update", "u", false, "allow updating already installed tools") rootCmd.AddCommand(installCmd) }