diff --git a/cmd/hauler/cli/store/info.go b/cmd/hauler/cli/store/info.go index 8be77b6..91c53fa 100644 --- a/cmd/hauler/cli/store/info.go +++ b/cmd/hauler/cli/store/info.go @@ -22,6 +22,7 @@ type InfoOpts struct { OutputFormat string TypeFilter string SizeUnit string + ListRepos bool } func (o *InfoOpts) AddFlags(cmd *cobra.Command) { @@ -29,6 +30,7 @@ func (o *InfoOpts) AddFlags(cmd *cobra.Command) { f.StringVarP(&o.OutputFormat, "output", "o", "table", "Output format (table, json)") f.StringVarP(&o.TypeFilter, "type", "t", "all", "Filter on type (image, chart, file, sigs, atts, sbom)") + f.BoolVar(&o.ListRepos, "list-repos", false, "List all repository names") // TODO: Regex/globbing } @@ -121,6 +123,11 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error { return err } + if o.ListRepos { + buildListRepos(items...) + return nil + } + // sort items by ref and arch sort.Sort(byReferenceAndArch(items)) @@ -135,6 +142,30 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error { return nil } +func buildListRepos(items ...item) { + // Create map to track unique repository names + repos := make(map[string]bool) + + for _, i := range items { + repoName := "" + for j := 0; j < len(i.Reference); j++ { + if i.Reference[j] == '/' { + repoName = i.Reference[:j] + break + } + } + if repoName == "" { + repoName = i.Reference + } + repos[repoName] = true + } + + // Collect and print unique repository names + for repoName := range repos { + fmt.Println(repoName) + } +} + func buildTable(items ...item) { // Create a table for the results table := tablewriter.NewWriter(os.Stdout)