Skip to content

Commit

Permalink
Merge pull request #25 from MrLYC/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MrLYC authored May 13, 2023
2 parents 5fe668e + 6439e29 commit bddd88c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CMDR
[![test](https://github.com/MrLYC/cmdr/actions/workflows/unittest.yml/badge.svg)](https://github.com/MrLYC/cmdr/actions/workflows/unittest.yml) [![codecov](https://codecov.io/gh/MrLYC/cmdr/branch/master/graph/badge.svg?token=mo4TJP4mQt)](https://codecov.io/gh/MrLYC/cmdr) ![Go version](https://img.shields.io/github/go-mod/go-version/mrlyc/cmdr) ![release](https://img.shields.io/github/v/release/mrlyc/cmdr?label=version)
[![test](https://github.com/MrLYC/cmdr/actions/workflows/test.yml/badge.svg)](https://github.com/MrLYC/cmdr/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/MrLYC/cmdr/branch/master/graph/badge.svg?token=mo4TJP4mQt)](https://codecov.io/gh/MrLYC/cmdr) ![Go version](https://img.shields.io/github/go-mod/go-version/mrlyc/cmdr) ![release](https://img.shields.io/github/v/release/mrlyc/cmdr?label=version)

CMDR is a simple command version management tool that helps you quickly switch from multiple command versions.

Expand Down
24 changes: 8 additions & 16 deletions core/initializer/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ func (c *CmdrUpdater) getActivatedCmdrVersion() string {
return command.GetVersion()
}

func (c *CmdrUpdater) install() error {
_, err := c.manager.Define(c.name, c.version, c.location)
if err != nil {
return errors.Wrapf(err, "failed to define command %s", c.name)
}

err = c.manager.Activate(c.name, c.version)
if err != nil {
return errors.Wrapf(err, "failed to activate command %s", c.name)
}

return nil
}

func (c *CmdrUpdater) removeLegacies(safeVersions []string) error {
logger := core.GetLogger()

Expand All @@ -69,6 +55,7 @@ func (c *CmdrUpdater) removeLegacies(safeVersions []string) error {
logger.Debug("checking legacy command", map[string]interface{}{
"command": command,
})

if command.GetActivated() {
continue
}
Expand Down Expand Up @@ -112,12 +99,17 @@ func (c *CmdrUpdater) Init(isUpgrade bool) error {
})

if !isUpgrade {
err := c.install()
_, err := c.manager.Define(c.name, c.version, c.location)
if err != nil {
return errors.WithMessagef(err, "failed to install command %s", c.name)
return errors.Wrapf(err, "failed to define command %s", c.name)
}
}

err := c.manager.Activate(c.name, c.version)
if err != nil {
return errors.Wrapf(err, "failed to activate command %s", c.name)
}

return c.removeLegacies(safeVersion)
}

Expand Down
6 changes: 6 additions & 0 deletions core/initializer/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ var _ = Describe("Command", func() {
Expect(updater.Init(false)).To(Succeed())
})

It("should upgrade cmdr", func() {
manager.EXPECT().Activate(name, version)
manager.EXPECT().Undefine(name, legacyCommand.GetVersion())

Expect(updater.Init(true)).To(Succeed())
})
})

0 comments on commit bddd88c

Please sign in to comment.