-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement outdated command #2497
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This allow to present all new versions available for the pkg installed. It is a lot useful because otherwise you need to check this manually.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package boxcli | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
"go.jetpack.io/devbox/internal/devbox" | ||
"go.jetpack.io/devbox/internal/devbox/devopt" | ||
) | ||
|
||
func outdatedCmd() *cobra.Command { | ||
flags := listCmdFlags{} | ||
command := &cobra.Command{ | ||
Use: "outdated", | ||
Short: "Show all outdated packages", | ||
Args: cobra.MaximumNArgs(0), | ||
PreRunE: ensureNixInstalled, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
box, err := devbox.Open(&devopt.Opts{ | ||
Dir: flags.config.path, | ||
Stderr: cmd.ErrOrStderr(), | ||
}) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
resutls, err := box.Outdated(cmd.Context()) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
if len(resutls) == 0 { | ||
cmd.Println("Your packages are up to date!") | ||
return nil | ||
} | ||
|
||
cmd.Println("The following packages can be updated:") | ||
for pkg, version := range resutls { | ||
cmd.Printf(" * %-30s %s -> %s\n", pkg, version.Current, version.Latest) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
return command | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ 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" | ||
|
@@ -43,6 +44,48 @@ const StateOutOfDateMessage = "Your devbox environment may be out of date. Run % | |
// packages.go has functions for adding, removing and getting info about nix | ||
// packages | ||
|
||
type UpdateVersion struct { | ||
Current string | ||
Latest string | ||
} | ||
|
||
// Outdated returns a map of package names to their available latest version. | ||
func (d *Devbox) Outdated(ctx context.Context) (map[string]UpdateVersion, error) { | ||
ctx, task := trace.NewTask(ctx, "devboxOutdated") | ||
defer task.End() | ||
|
||
outdatedPackages := map[string]UpdateVersion{} | ||
|
||
for _, pkg := range d.AllPackages() { | ||
if strings.HasSuffix(pkg.Versioned(), "latest") { | ||
continue | ||
} | ||
guerinoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result, err := searcher.Client().Search(ctx, pkg.CanonicalName()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return outdatedPackages, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guerinoni I think we need this function to be rewritten as so. I created this patch via copying here for clarity:
wdyt @gcurtis @mikeland73 ? The benefit of this is that it also works for
I don't think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I aligned with this patch :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not runx? The versions are correct. Ideally we could also do it for flakes as well but our current flake update mechanism is a bit broken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh good point, I forgot runx updating works properly. So all good |
||
} | ||
|
||
// Add adds the `pkgs` to the config (i.e. devbox.json) and nix profile for this | ||
// devbox project | ||
func (d *Devbox) Add(ctx context.Context, pkgsNames []string, opts devopt.AddOpts) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, would prefer to use a slice over map. We don't need random access or deduplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gcurtis may not like this but we could just return
[]lo.Tuple2[*lockfile.Package, *lockfile.Package]
that way we don't have to create a new struct at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm I don't mind the struct. Its nice to have the names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
map
is just a convenience for the name. Otherwise you'd have to add aName
field to the struct. That works tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How you prefer guys, here map doesn't create any performance problems, it is just a matter of some seconds to run the command, I chose readability over little optimization