From 08ff6df380de65a4d253bbd02fc58f66c0e4eefb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 6 Nov 2024 17:25:01 +0100 Subject: [PATCH] fixup! allow "{distro,arch,type}:" prefix to build,manifest to make copy/paste friendly --- cmd/image-builder/filters.go | 2 +- cmd/image-builder/main.go | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/image-builder/filters.go b/cmd/image-builder/filters.go index 774def7080..500b73d77d 100644 --- a/cmd/image-builder/filters.go +++ b/cmd/image-builder/filters.go @@ -23,7 +23,7 @@ func getOneImage(distroName, imgTypeStr, archStr string) (*imagefilter.Result, e } filterExprs := []string{ - fmt.Sprintf("name:%s", distroName), + fmt.Sprintf("distro:%s", distroName), fmt.Sprintf("arch:%s", archStr), fmt.Sprintf("type:%s", imgTypeStr), } diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 76ecf695c9..b06d92f19d 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -4,6 +4,7 @@ import ( "io" "log" "os" + "strings" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -27,11 +28,12 @@ func cmdListImages(cmd *cobra.Command, args []string) error { } func cmdManifest(cmd *cobra.Command, args []string) error { - distroName := args[0] - imgType := args[1] + // support prefixes to make it easy to copy/paste from list-images + distroName := strings.TrimPrefix(args[0], "distro:") + imgType := strings.TrimPrefix(args[1], "type:") var archStr string if len(args) > 2 { - archStr = args[2] + archStr = strings.TrimPrefix(args[2], "arch:") } else { archStr = arch.Current().String() } @@ -40,8 +42,9 @@ func cmdManifest(cmd *cobra.Command, args []string) error { } func cmdBuild(cmd *cobra.Command, args []string) error { - distroName := args[0] - imgType := args[1] + // support prefixes to make it easy to copy/paste from list-images + distroName := strings.TrimPrefix(args[0], "distro:") + imgType := strings.TrimPrefix(args[1], "type:") return buildImage(osStdout, distroName, imgType) } @@ -78,8 +81,9 @@ operating sytsems like centos and RHEL with easy customizations support.`, Short: "Build manifest for the given distro/image-type, e.g. centos-9 qcow2", RunE: cmdManifest, SilenceUsage: true, - Args: cobra.MinimumNArgs(2), - Hidden: true, + // XXX: show error with available types if only one arg given + Args: cobra.MinimumNArgs(2), + Hidden: true, } rootCmd.AddCommand(manifestCmd) @@ -88,7 +92,8 @@ operating sytsems like centos and RHEL with easy customizations support.`, Short: "Build the given distro/image-type, e.g. centos-9 qcow2", RunE: cmdBuild, SilenceUsage: true, - Args: cobra.ExactArgs(2), + // XXX: show error with available types if only one arg given + Args: cobra.ExactArgs(2), } rootCmd.AddCommand(buildCmd) // XXX: add --output=text,json and streaming