Skip to content

Commit

Permalink
feat(pkg): Remove unbuilt targets from multi select prompt (#1288)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <[email protected]>
Approved-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc authored Feb 21, 2024
2 parents a110c44 + 93a1cf9 commit d9d9e9d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions internal/cli/kraft/pkg/packager_kraftfile_unikraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package pkg
import (
"context"
"fmt"
"os"
"slices"
"strings"

"github.com/mattn/go-shellwords"
Expand Down Expand Up @@ -62,9 +64,21 @@ func (p *packagerKraftfileUnikraft) Pack(ctx context.Context, opts *PkgOptions,
}

if len(selected) > 1 && !config.G[config.KraftKit](ctx).NoPrompt {
selected, err = multiselect.MultiSelect[target.Target]("select what to package", opts.Project.Targets()...)
if err != nil {
return nil, err
// Remove targets which do not have a compiled kernel.
targets := slices.DeleteFunc(opts.Project.Targets(), func(targ target.Target) bool {
_, err := os.Stat(targ.Kernel())
return err != nil
})

if len(targets) == 0 {
return nil, fmt.Errorf("no targets with a compiled kernel found")
} else if len(targets) == 1 {
selected = targets
} else {
selected, err = multiselect.MultiSelect[target.Target]("select built kernel to package", targets...)
if err != nil {
return nil, err
}
}
}

Expand Down

0 comments on commit d9d9e9d

Please sign in to comment.