From 6074d36897812d3f26e19b8085ca2ec5eea2a602 Mon Sep 17 00:00:00 2001 From: Denis Khoshaba Date: Tue, 14 May 2024 02:25:52 +1000 Subject: [PATCH] make the default arch the system arch (#12) --- cmd/anchor/root.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/anchor/root.go b/cmd/anchor/root.go index 761ec79..0cce38f 100644 --- a/cmd/anchor/root.go +++ b/cmd/anchor/root.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "path/filepath" + "runtime" "strings" "syscall" @@ -29,7 +30,7 @@ func init() { rootCmd.PersistentFlags(). StringP("output", "o", "Dockerfile", "Name of the output dockerfile. If using multiple architectures, the architecture will be appended to the output file name") rootCmd.PersistentFlags(). - StringP("architectures", "a", "arm64", "Comma delimited list of architectures to anchor") + StringP("architectures", "a", "", "Comma delimited list of architectures to anchor: \"amd64\" and \"arm64\" are supported. If the flag is not used, the system architecture will be used") rootCmd.PersistentFlags(). BoolP("dry-run", "", false, "Write the output to stdout instead of a file") rootCmd.PersistentFlags(). @@ -69,6 +70,12 @@ var rootCmd = &cobra.Command{ if err != nil { return err } + if architectures == "" { + architectures, err = getArchitecture() + if err != nil { + return err + } + } input, err := cmd.Flags().GetString("input") if err != nil { return err @@ -171,3 +178,14 @@ func Execute() { os.Exit(1) } } + +func getArchitecture() (string, error) { + switch runtime.GOARCH { + case "amd64": + return "amd64", nil + case "arm64": + return "arm64", nil + default: + return "unknown", fmt.Errorf("unsupported architecture: %s", runtime.GOARCH) + } +}