From 8d1306f7fcb1e65d7ce7ce5494db1b248cd03026 Mon Sep 17 00:00:00 2001 From: Shenjun Ma Date: Wed, 6 Jan 2021 01:38:18 +0800 Subject: [PATCH] pd-ctl: set exit code for invalid command Signed-off-by: Shenjun Ma --- tools/pd-ctl/pdctl/ctl.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/pd-ctl/pdctl/ctl.go b/tools/pd-ctl/pdctl/ctl.go index 20693a51498..a8ad60fc82b 100644 --- a/tools/pd-ctl/pdctl/ctl.go +++ b/tools/pd-ctl/pdctl/ctl.go @@ -136,26 +136,30 @@ func hiddenFlag(cmd *cobra.Command) { // MainStart start main command func MainStart(args []string) { - startCmd(getMainCmd, args) + if err := startCmd(getMainCmd, args); err != nil { + os.Exit(1) + } } // Start start interact command func Start(args []string) { - startCmd(getInteractCmd, args) + _ = startCmd(getInteractCmd, args) } -func startCmd(getCmd func([]string) *cobra.Command, args []string) { +func startCmd(getCmd func([]string) *cobra.Command, args []string) error { rootCmd := getCmd(args) if len(commandFlags.CAPath) != 0 { if err := command.InitHTTPSClient(commandFlags.CAPath, commandFlags.CertPath, commandFlags.KeyPath); err != nil { rootCmd.Println(err) - return + return err } } if err := rootCmd.Execute(); err != nil { rootCmd.Println(err) + return err } + return nil } func loop() {