diff --git a/cmd/docker-variant/common.go b/cmd/docker-variant/common.go new file mode 100644 index 0000000..d071d38 --- /dev/null +++ b/cmd/docker-variant/common.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/achimnol/docker-variant/pkg/oci" +) + +// registryFlags carries the flags shared by every registry-touching +// subcommand. +type registryFlags struct { + plainHTTP bool +} + +func (f *registryFlags) add(cmd *cobra.Command) { + cmd.Flags().BoolVar(&f.plainHTTP, "plain-http", false, "use HTTP for the registry (loopback registries always do)") +} + +func (f *registryFlags) client() (*oci.Client, error) { + return oci.NewClient(f.plainHTTP) +} + +// versionRef parses a "/:" argument. +func versionRef(arg string) (oci.Ref, error) { + ref, err := oci.ParseRef(arg) + if err != nil { + return oci.Ref{}, err + } + if ref.Tag == "" { + return oci.Ref{}, fmt.Errorf("reference %q must include the base version as its tag", arg) + } + return ref, nil +} diff --git a/cmd/docker-variant/indexcmd.go b/cmd/docker-variant/indexcmd.go new file mode 100644 index 0000000..6cf4103 --- /dev/null +++ b/cmd/docker-variant/indexcmd.go @@ -0,0 +1,62 @@ +package main + +import ( + "fmt" + "maps" + "slices" + + "github.com/spf13/cobra" + + "github.com/achimnol/docker-variant/pkg/variant" +) + +func newIndexCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "index", + Short: "Manage variant index artifacts", + } + cmd.AddCommand(newIndexUpdateCommand()) + return cmd +} + +func newIndexUpdateCommand() *cobra.Command { + var regFlags registryFlags + cmd := &cobra.Command{ + Use: "update REGISTRY/REPOSITORY:VERSION", + Short: "Rebuild the variant index by scanning the repository's tags", + Long: "Scans the repository for -