Skip to content

Commit

Permalink
fixup! allow "{distro,arch,type}:" prefix to build,manifest to make c…
Browse files Browse the repository at this point in the history
…opy/paste friendly
  • Loading branch information
mvo5 committed Nov 12, 2024
1 parent b052e23 commit caf0c91
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/image-builder/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
21 changes: 13 additions & 8 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"log"
"os"
"strings"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -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()
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit caf0c91

Please sign in to comment.