Skip to content

[info] Modernize via search api #1376

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

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/samber/lo"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/impl/generate"
"go.jetpack.io/devbox/internal/searcher"
"go.jetpack.io/devbox/internal/shellgen"
"go.jetpack.io/devbox/internal/telemetry"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -340,24 +341,32 @@ func (d *Devbox) Info(ctx context.Context, pkg string, markdown bool) error {
ctx, task := trace.NewTask(ctx, "devboxInfo")
defer task.End()

locked, err := d.lockfile.Resolve(pkg)
name, version, isVersioned := searcher.ParseVersionedPackage(pkg)
if !isVersioned {
name = pkg
version = "latest"
}

packageVersion, err := searcher.Client().Resolve(name, version)
if err != nil {
return err
// This is not ideal. Search service should return valid response we
// can parse
return usererr.WithUserMessage(err, "No results found for %q\n", pkg)
}

results, _ := nix.Search(locked.Resolved)
if len(results) == 0 {
if packageVersion == nil {
_, err := fmt.Fprintf(d.writer, "Package %s not found\n", pkg)
return errors.WithStack(err)
}

// we should only have one result
info := lo.Values(results)[0]
if _, err := fmt.Fprintf(
d.writer,
"%s%s\n",
"%s%s %s\n%s\n",
lo.Ternary(markdown, "## ", ""),
info,
packageVersion.Name,
packageVersion.Version,
packageVersion.Summary,
); err != nil {
return errors.WithStack(err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/nix/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Info struct {
// if we know exactly which version we are using
AttributeKey string
PName string
Summary string
Version string
}

Expand Down
1 change: 1 addition & 0 deletions internal/searcher/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type PackageInfo struct {
MetaVersion []string `json:"meta_version"`
AttrPaths []string `json:"attr_paths"`
Version string `json:"version"`
Summary string `json:"summary"`
}