tools/minimalImageBuildTool/cmd/root.go (35 lines of code) (raw):
package cmd
import (
"context"
"fmt"
"log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/aws/eks-distro-build-tooling/tools/minimalImageBuildTool/pkg/logger"
)
var rootCmd = &cobra.Command{
Use: "minimal-image-build",
Short: "Minimial Image CLI",
Long: `Use minimal-image-build to create your own minimal image based off Amazon Linux`,
PersistentPreRun: rootPersistentPreRun,
}
func init() {
rootCmd.PersistentFlags().IntP("verbosity", "v", 0, "Set the log level verbosity")
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {
log.Fatalf("failed to bind flags for root: %v", err)
}
}
func rootPersistentPreRun(cmd *cobra.Command, args []string) {
if err := initLogger(); err != nil {
log.Fatal(err)
}
}
func initLogger() error {
if err := logger.InitZap(viper.GetInt("verbosity")); err != nil {
return fmt.Errorf("failed init zap logger in root command: %v", err)
}
return nil
}
func Execute() error {
return rootCmd.ExecuteContext(context.Background())
}