-
Notifications
You must be signed in to change notification settings - Fork 269
[sandboxes] devbox ls: print versions #2277
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package boxcli | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
@@ -32,8 +33,26 @@ func listCmd() *cobra.Command { | |
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
for _, p := range box.AllPackageNamesIncludingRemovedTriggerPackages() { | ||
fmt.Fprintf(cmd.OutOrStdout(), "* %s\n", p) | ||
|
||
for _, pkg := range box.AllPackagesIncludingRemovedTriggerPackages() { | ||
resolvedVersion, err := pkg.ResolvedVersion() | ||
if err != nil { | ||
// Continue to print the package even if we can't resolve the version | ||
// so that the user can see the error for this package, as well as get the | ||
// results for the other packages | ||
resolvedVersion = "<error resolving version>" | ||
} | ||
msg := "" | ||
|
||
// Print the resolved version, unless the user has specified a version already | ||
if strings.HasSuffix(pkg.Versioned(), "latest") && resolvedVersion != "" { | ||
// Runx packages have a "v" prefix (why?). Trim for consistency. | ||
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. technically semver has (or can have?) a prefix |
||
resolvedVersion = strings.TrimPrefix(resolvedVersion, "v") | ||
msg = fmt.Sprintf("* %s - %s\n", pkg.Versioned(), resolvedVersion) | ||
} else { | ||
msg = fmt.Sprintf("* %s\n", pkg.Versioned()) | ||
} | ||
fmt.Fprint(cmd.OutOrStdout(), msg) | ||
} | ||
return nil | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,12 +842,17 @@ func (d *Devbox) flakeDir() string { | |
// flakes (lockfile vs devbox list) | ||
func (d *Devbox) AllPackageNamesIncludingRemovedTriggerPackages() []string { | ||
result := []string{} | ||
for _, p := range d.cfg.Packages(true /*includeRemovedTriggerPackages*/) { | ||
result = append(result, p.VersionedName()) | ||
for _, p := range d.AllPackagesIncludingRemovedTriggerPackages() { | ||
result = append(result, p.Versioned()) | ||
} | ||
return result | ||
} | ||
|
||
func (d *Devbox) AllPackagesIncludingRemovedTriggerPackages() []*devpkg.Package { | ||
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. Change 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. done There's a small subtle difference that I think is okay in practice, but let me call it out.
I think this doesn't matter in practice, because we always append |
||
packages := d.cfg.Packages(true /*includeRemovedTriggerPackages*/) | ||
return devpkg.PackagesFromConfig(packages, d.lockfile) | ||
} | ||
|
||
// AllPackages returns the packages that are defined in devbox.json and | ||
// recursively added by plugins. | ||
// NOTE: This will not return packages removed by their plugin with the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -832,3 +832,15 @@ func packageInstallErrorHandler(err error, pkg *Package, installableOrEmpty stri | |
|
||
return usererr.WithUserMessage(err, "error installing package %s", pkg.Raw) | ||
} | ||
|
||
func (p *Package) ResolvedVersion() (string, error) { | ||
if err := p.resolve(); err != nil { | ||
return "", err | ||
} | ||
Comment on lines
+837
to
+839
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. If package is not in lockfile this is just current resolved version, but that's probably ok. |
||
lockPackage := p.lockfile.Get(p.Raw) | ||
// Flake packages don't have any values in the lockfile | ||
if lockPackage == nil { | ||
return "", nil | ||
} | ||
return p.lockfile.Get(p.Raw).Version, nil | ||
} |
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.
Maybe omit the version from the list and print it on stderr at the end?