From 50b0e5a4b00d3c57a8f560cd7ec75ee42d42a06d Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 9 Feb 2023 01:04:09 +0700 Subject: [PATCH] cmd/ctrld: use proper exit codes for status command While at it, disable sort commands, so help output will be in order. Updates #48 --- cmd/ctrld/cli.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/ctrld/cli.go b/cmd/ctrld/cli.go index df96bde..cd18ee1 100644 --- a/cmd/ctrld/cli.go +++ b/cmd/ctrld/cli.go @@ -56,6 +56,7 @@ func initCLI() { // Enable opening via explorer.exe on Windows. // See: https://github.com/spf13/cobra/issues/844. cobra.MousetrapHelpText = "" + cobra.EnableCommandSorting = false rootCmd := &cobra.Command{ Use: "ctrld", @@ -177,7 +178,7 @@ func initCLI() { startCmd := &cobra.Command{ PreRun: checkHasElevatedPrivilege, Use: "start", - Short: "Start the ctrld service", + Short: "Install and start the ctrld service", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { sc := &service.Config{} @@ -293,15 +294,18 @@ func initCLI() { status, err := s.Status() if err != nil { stderrMsg(err.Error()) - return + os.Exit(1) } switch status { case service.StatusUnknown: stdoutMsg("Unknown status") + os.Exit(2) case service.StatusRunning: stdoutMsg("Service is running") + os.Exit(0) case service.StatusStopped: stdoutMsg("Service is stopped") + os.Exit(1) } }, } @@ -309,7 +313,7 @@ func initCLI() { uninstallCmd := &cobra.Command{ PreRun: checkHasElevatedPrivilege, Use: "uninstall", - Short: "Uninstall the ctrld service", + Short: "Stop and uninstall the ctrld service", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { prog := &prog{}