Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Lagoja authored and guerinoni committed Feb 4, 2025
1 parent 9672a6d commit 1878258
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 67 deletions.
31 changes: 29 additions & 2 deletions internal/boxcli/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
// Copyright 2025 Jetify Inc. and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.

package boxcli
Expand All @@ -15,7 +15,8 @@ import (
)

type listCmdFlags struct {
config configFlags
config configFlags
outdated bool
}

func listCmd() *cobra.Command {
Expand All @@ -34,6 +35,10 @@ func listCmd() *cobra.Command {
return errors.WithStack(err)
}

if flags.outdated {
return printOutdatedPackages(cmd, box)
}

for _, pkg := range box.AllPackagesIncludingRemovedTriggerPackages() {
resolvedVersion, err := pkg.ResolvedVersion()
if err != nil {
Expand All @@ -57,6 +62,28 @@ func listCmd() *cobra.Command {
return nil
},
}

cmd.Flags().BoolVar(&flags.outdated, "outdated", false, "List outdated packages")
flags.config.register(cmd)
return cmd
}

// printOutdatedPackages prints a list of outdated packages.
func printOutdatedPackages(cmd *cobra.Command, box *devbox.Devbox) error {
results, err := box.Outdated(cmd.Context())
if err != nil {
return errors.WithStack(err)
}

if len(results) == 0 {
cmd.Println("Your packages are up to date!")
return nil
}

cmd.Println("The following packages can be updated:")
for pkg, version := range results {
cmd.Printf(" * %-30s %s -> %s\n", pkg, version.Current, version.Latest)
}

return nil
}
45 changes: 0 additions & 45 deletions internal/boxcli/outdated.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/boxcli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func RootCmd() *cobra.Command {
command.AddCommand(infoCmd())
command.AddCommand(initCmd())
command.AddCommand(installCmd())
command.AddCommand(outdatedCmd())
command.AddCommand(integrateCmd())
command.AddCommand(listCmd())
command.AddCommand(logCmd())
Expand Down
29 changes: 10 additions & 19 deletions internal/devbox/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
"go.jetpack.io/devbox/internal/lock"
"go.jetpack.io/devbox/internal/searcher"
"go.jetpack.io/devbox/internal/setup"
"go.jetpack.io/devbox/internal/shellgen"
"go.jetpack.io/devbox/internal/telemetry"
Expand Down Expand Up @@ -54,33 +53,25 @@ func (d *Devbox) Outdated(ctx context.Context) (map[string]UpdateVersion, error)
ctx, task := trace.NewTask(ctx, "devboxOutdated")
defer task.End()

lockfile := d.Lockfile()
outdatedPackages := map[string]UpdateVersion{}

for _, pkg := range d.AllPackages() {
if strings.HasSuffix(pkg.Versioned(), "latest") {
// For non-devbox packages, like flakes or runx, we can skip for now
if !pkg.IsDevboxPackage {
continue
}

result, err := searcher.Client().Search(ctx, pkg.CanonicalName())
lockPackage, err := lockfile.FetchResolvedPackage(pkg.Versioned())
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to fetch resolved package")
}

for _, p := range result.Packages {
if p.Name == pkg.CanonicalName() {
for _, v := range p.Versions {
vv, err := pkg.ResolvedVersion()
if err != nil {
return nil, err
}

if v.Version > vv {
outdatedPackages[p.Name] = UpdateVersion{Current: vv, Latest: v.Version}
break
}
}
}
existingLockPackage := lockfile.Packages[pkg.Raw]
if lockPackage.Version == existingLockPackage.Version {
continue
}

outdatedPackages[pkg.Versioned()] = UpdateVersion{Current: existingLockPackage.Version, Latest: lockPackage.Version}
}

return outdatedPackages, nil
Expand Down

0 comments on commit 1878258

Please sign in to comment.