|
| 1 | +package olmv1 |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | + "github.com/spf13/pflag" |
| 8 | + |
| 9 | + "github.com/operator-framework/kubectl-operator/internal/cmd/internal/log" |
| 10 | + v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action" |
| 11 | + "github.com/operator-framework/kubectl-operator/pkg/action" |
| 12 | +) |
| 13 | + |
| 14 | +// NewCatalogCreateCmd allows creating a new catalog |
| 15 | +func NewCatalogCreateCmd(cfg *action.Configuration) *cobra.Command { |
| 16 | + i := v1action.NewCatalogCreate(cfg) |
| 17 | + i.Logf = log.Printf |
| 18 | + |
| 19 | + cmd := &cobra.Command{ |
| 20 | + Use: "catalog <catalog_name> <image_source_ref>", |
| 21 | + Aliases: []string{"catalogs <catalog_name> <image_source_ref>"}, |
| 22 | + Args: cobra.ExactArgs(2), |
| 23 | + Short: "Create a new catalog", |
| 24 | + Run: func(cmd *cobra.Command, args []string) { |
| 25 | + i.CatalogName = args[0] |
| 26 | + i.ImageSourceRef = args[1] |
| 27 | + |
| 28 | + if err := i.Run(cmd.Context()); err != nil { |
| 29 | + log.Fatalf("failed to create catalog %q: %v", i.CatalogName, err) |
| 30 | + } |
| 31 | + log.Printf("catalog %q created", i.CatalogName) |
| 32 | + }, |
| 33 | + } |
| 34 | + bindCatalogCreateFlags(cmd.Flags(), i) |
| 35 | + |
| 36 | + return cmd |
| 37 | +} |
| 38 | + |
| 39 | +func bindCatalogCreateFlags(fs *pflag.FlagSet, i *v1action.CatalogCreate) { |
| 40 | + fs.Int32Var(&i.Priority, "priority", 0, "priority of the catalog") |
| 41 | + fs.BoolVar(&i.Available, "available", true, "availability of the catalog") |
| 42 | + fs.IntVar(&i.PollIntervalMinutes, "source-poll-interval-minutes", 10, "source poll interval [in minutes]") |
| 43 | + fs.StringToStringVar(&i.Labels, "labels", map[string]string{}, "catalog labels") |
| 44 | + fs.DurationVar(&i.CleanupTimeout, "cleanup-timeout", time.Minute, "the amount of time to wait before cancelling cleanup") |
| 45 | +} |
0 commit comments