Skip to content

Commit

Permalink
feat(list): Wrap the Catalog lookup with a processtree (#937)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed Oct 26, 2023
2 parents 386f257 + 6c4d26f commit 72463b0
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions internal/cli/kraft/pkg/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"

"kraftkit.sh/config"
"kraftkit.sh/tui/processtree"
"kraftkit.sh/unikraft/app"

"kraftkit.sh/cmdfactory"
Expand Down Expand Up @@ -121,14 +123,42 @@ func (opts *ListOptions) Run(ctx context.Context, args []string) error {

fmt.Fprint(iostreams.G(ctx).Out, project.PrintInfo(ctx))
} else {
found, err := packmanager.G(ctx).Catalog(ctx,
packmanager.WithUpdate(opts.Update),
packmanager.WithTypes(types...),
var found []pack.Package

parallel := !config.G[config.KraftKit](ctx).NoParallel
norender := log.LoggerTypeFromString(config.G[config.KraftKit](ctx).Log.Type) != log.FANCY

treemodel, err := processtree.NewProcessTree(
ctx,
[]processtree.ProcessTreeOption{
processtree.IsParallel(parallel),
processtree.WithRenderer(norender),
processtree.WithFailFast(true),
processtree.WithHideOnSuccess(true),
},
processtree.NewProcessTreeItem(
"updating index...", "",
func(ctx context.Context) error {
found, err = packmanager.G(ctx).Catalog(ctx,
packmanager.WithUpdate(opts.Update),
packmanager.WithTypes(types...),
)
if err != nil {
return err
}

return nil
},
),
)
if err != nil {
return err
}

if err := treemodel.Start(); err != nil {
return fmt.Errorf("could not complete search: %v", err)
}

for _, p := range found {
format := p.Format().String()
if _, ok := packages[format]; !ok {
Expand All @@ -139,6 +169,11 @@ func (opts *ListOptions) Run(ctx context.Context, args []string) error {
}
}

if len(packages) == 0 {
log.G(ctx).Info("no packages found")
return nil
}

for format, packs := range packages {
// Sort packages by type, name, version, format
sort.Slice(packs, func(i, j int) bool {
Expand Down

0 comments on commit 72463b0

Please sign in to comment.