Merge branch 'rancherfederal:main' into main

This commit is contained in:
Zack Brady
2023-12-20 00:31:44 -05:00
committed by GitHub
2 changed files with 20 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package cli
import (
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"
"fmt"
"github.com/rancherfederal/hauler/cmd/hauler/cli/store"
)
@@ -155,6 +156,8 @@ func addStoreSave() *cobra.Command {
func addStoreInfo() *cobra.Command {
o := &store.InfoOpts{RootOpts: rootStoreOpts}
var allowedValues = []string{"image", "chart", "file", "all"}
cmd := &cobra.Command{
Use: "info",
Short: "Print out information about the store",
@@ -167,8 +170,13 @@ func addStoreInfo() *cobra.Command {
if err != nil {
return err
}
return store.InfoCmd(ctx, o, s)
for _, allowed := range allowedValues {
if o.TypeFilter == allowed {
return store.InfoCmd(ctx, o, s)
}
}
return fmt.Errorf("type must be one of %v", allowedValues)
},
}
o.AddFlags(cmd)

View File

@@ -22,6 +22,7 @@ type InfoOpts struct {
*RootOpts
OutputFormat string
TypeFilter string
SizeUnit string
}
@@ -29,6 +30,7 @@ func (o *InfoOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()
f.StringVarP(&o.OutputFormat, "output", "o", "table", "Output format (table, json)")
f.StringVarP(&o.TypeFilter, "type", "t", "all", "Filter on type (image, chart, file)")
// TODO: Regex/globbing
}
@@ -64,7 +66,7 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
return err
}
i := newItem(s, desc, internalManifest, internalDesc.Platform.Architecture)
i := newItem(s, desc, internalManifest, internalDesc.Platform.Architecture, o)
var emptyItem item
if i != emptyItem {
items = append(items, i)
@@ -89,7 +91,7 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
return err
}
i := newItem(s, desc, m, internalManifest.Architecture)
i := newItem(s, desc, m, internalManifest.Architecture, o)
var emptyItem item
if i != emptyItem {
items = append(items, i)
@@ -101,7 +103,7 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
return err
}
i := newItem(s, desc, m, "-")
i := newItem(s, desc, m, "-", o)
var emptyItem item
if i != emptyItem {
items = append(items, i)
@@ -177,7 +179,7 @@ func (a byReferenceAndArch) Less(i, j int) bool {
return a[i].Reference < a[j].Reference
}
func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, arch string) item {
func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, arch string, o *InfoOpts) item {
// skip listing cosign items
if desc.Annotations["kind"] == "dev.cosignproject.cosign/atts" ||
desc.Annotations["kind"] == "dev.cosignproject.cosign/sigs" ||
@@ -208,6 +210,10 @@ func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, arch
return item{}
}
if o.TypeFilter != "all" && ctype != o.TypeFilter {
return item{}
}
return item{
Reference: ref.Name(),
Type: ctype,