From b3cbeb81ef943dfc423d06b51caa25b43cda29ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=AD=E6=9D=91=20=E5=BC=98=E6=AD=A6?= Date: Sat, 28 Nov 2020 18:25:59 +0900 Subject: [PATCH] validate only command --- cmd/eskeeper/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmd/eskeeper/main.go b/cmd/eskeeper/main.go index 4318423..eec0a61 100644 --- a/cmd/eskeeper/main.go +++ b/cmd/eskeeper/main.go @@ -46,7 +46,36 @@ var rootCmd = &cobra.Command{ }, } +var validate = &cobra.Command{ + Use: "validate", + Short: "Validates config", + Run: func(cmd *cobra.Command, args []string) { + k, err := eskeeper.New( + []string{}, + eskeeper.Verbose(true), + ) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + if terminal.IsTerminal(int(os.Stdin.Fd())) { + fmt.Println("Currently does not support interactive mode") + os.Exit(1) + } + + ctx := context.Background() + err = k.Validate(ctx, os.Stdin) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println("pass") + }, +} + func init() { + rootCmd.AddCommand(validate) viper.SetEnvPrefix("eskeeper") viper.AutomaticEnv()