Skip to content

Commit c672635

Browse files
committed
devbox.findPackagesByName should be constructed from Config packages
1 parent 89ef96b commit c672635

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

internal/impl/devbox.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,22 +992,22 @@ func (d *Devbox) HasDeprecatedPackages() bool {
992992
return false
993993
}
994994

995-
func (d *Devbox) findPackageByName(name string) (string, error) {
996-
results := map[string]bool{}
995+
func (d *Devbox) findPackageByName(name string) (*devpkg.Package, error) {
996+
results := map[*devpkg.Package]bool{}
997997
for _, pkg := range d.configPackages() {
998998
if pkg.String() == name || pkg.CanonicalName() == name {
999-
results[pkg.String()] = true
999+
results[pkg] = true
10001000
}
10011001
}
10021002
if len(results) > 1 {
1003-
return "", usererr.New(
1003+
return nil, usererr.New(
10041004
"found multiple packages with name %s: %s. Please specify version",
10051005
name,
10061006
lo.Keys(results),
10071007
)
10081008
}
10091009
if len(results) == 0 {
1010-
return "", usererr.New("no package found with name %s", name)
1010+
return nil, usererr.New("no package found with name %s", name)
10111011
}
10121012
return lo.Keys(results)[0], nil
10131013
}

internal/impl/packages.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ func (d *Devbox) Add(ctx context.Context, pkgsNames ...string) error {
5757
// it. Ignore error (which is either missing or more than one). We search by
5858
// CanonicalName so any legacy or versioned packages will be removed if they
5959
// match.
60-
if name, _ := d.findPackageByName(pkg.CanonicalName()); name != "" {
60+
found, _ := d.findPackageByName(pkg.CanonicalName())
61+
// TODO savil: should name be found.Raw?
62+
if name := found.String(); name != "" {
6163
if err := d.Remove(ctx, name); err != nil {
6264
return err
6365
}
@@ -134,9 +136,10 @@ func (d *Devbox) Remove(ctx context.Context, pkgs ...string) error {
134136
missingPkgs := []string{}
135137
for _, pkg := range lo.Uniq(pkgs) {
136138
found, _ := d.findPackageByName(pkg)
137-
if found != "" {
138-
packagesToUninstall = append(packagesToUninstall, found)
139-
d.cfg.Packages.Remove(found)
139+
if found != nil {
140+
name := found.String() // TODO savil. should this be found.Raw?
141+
packagesToUninstall = append(packagesToUninstall, name)
142+
d.cfg.Packages.Remove(name)
140143
} else {
141144
missingPkgs = append(missingPkgs, pkg)
142145
}

internal/impl/update.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ func (d *Devbox) Update(ctx context.Context, pkgs ...string) error {
6666
}
6767

6868
func (d *Devbox) inputsToUpdate(pkgs ...string) ([]*devpkg.Package, error) {
69-
var pkgsToUpdate []string
69+
if len(pkgs) == 0 {
70+
return d.configPackages(), nil
71+
}
72+
73+
var pkgsToUpdate []*devpkg.Package
7074
for _, pkg := range pkgs {
7175
found, err := d.findPackageByName(pkg)
7276
if err != nil {
7377
return nil, err
7478
}
7579
pkgsToUpdate = append(pkgsToUpdate, found)
7680
}
77-
if len(pkgsToUpdate) == 0 {
78-
pkgsToUpdate = d.PackageNames()
79-
}
80-
81-
return devpkg.PackageFromStrings(pkgsToUpdate, d.lockfile), nil
81+
return pkgsToUpdate, nil
8282
}
8383

8484
func (d *Devbox) updateDevboxPackage(

0 commit comments

Comments
 (0)