-
Notifications
You must be signed in to change notification settings - Fork 51
/
upgrade_cmd.go
53 lines (45 loc) · 1.26 KB
/
upgrade_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package app
import (
"os"
"github.com/pkg/errors"
"github.com/cashapp/hermit"
"github.com/cashapp/hermit/envars"
"github.com/cashapp/hermit/manifest"
"github.com/cashapp/hermit/shell"
"github.com/cashapp/hermit/ui"
)
type upgradeCmd struct {
Packages []string `arg:"" optional:"" name:"package" help:"Packages to upgrade. If omitted, upgrades all installed packages." predictor:"installed-package"`
}
func (g *upgradeCmd) Run(l *ui.UI, env *hermit.Env) error {
packages := []*manifest.Package{}
installed, err := env.ListInstalled(l)
if err != nil {
return errors.WithStack(err)
}
if g.Packages != nil {
// check that the requested packages have been installed
packageNames := map[string]*manifest.Package{}
for _, pkg := range installed {
packageNames[pkg.Reference.Name] = pkg
}
for _, name := range g.Packages {
if packageNames[name] == nil {
return errors.Errorf("no installed package '%s' found.", name)
}
packages = append(packages, packageNames[name])
}
} else {
packages = installed
}
changes := shell.NewChanges(envars.Parse(os.Environ()))
// upgrade packages
for _, pkg := range packages {
c, err := env.Upgrade(l, pkg)
if err != nil {
return errors.WithStack(err)
}
changes = changes.Merge(c)
}
return nil
}