mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-23 01:27:13 +02:00
cmd/ctrld: use proper exit codes for status command
While at it, disable sort commands, so help output will be in order. Updates #48
This commit is contained in:
+7
-3
@@ -56,6 +56,7 @@ func initCLI() {
|
|||||||
// Enable opening via explorer.exe on Windows.
|
// Enable opening via explorer.exe on Windows.
|
||||||
// See: https://github.com/spf13/cobra/issues/844.
|
// See: https://github.com/spf13/cobra/issues/844.
|
||||||
cobra.MousetrapHelpText = ""
|
cobra.MousetrapHelpText = ""
|
||||||
|
cobra.EnableCommandSorting = false
|
||||||
|
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
Use: "ctrld",
|
Use: "ctrld",
|
||||||
@@ -177,7 +178,7 @@ func initCLI() {
|
|||||||
startCmd := &cobra.Command{
|
startCmd := &cobra.Command{
|
||||||
PreRun: checkHasElevatedPrivilege,
|
PreRun: checkHasElevatedPrivilege,
|
||||||
Use: "start",
|
Use: "start",
|
||||||
Short: "Start the ctrld service",
|
Short: "Install and start the ctrld service",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
sc := &service.Config{}
|
sc := &service.Config{}
|
||||||
@@ -293,15 +294,18 @@ func initCLI() {
|
|||||||
status, err := s.Status()
|
status, err := s.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stderrMsg(err.Error())
|
stderrMsg(err.Error())
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
switch status {
|
switch status {
|
||||||
case service.StatusUnknown:
|
case service.StatusUnknown:
|
||||||
stdoutMsg("Unknown status")
|
stdoutMsg("Unknown status")
|
||||||
|
os.Exit(2)
|
||||||
case service.StatusRunning:
|
case service.StatusRunning:
|
||||||
stdoutMsg("Service is running")
|
stdoutMsg("Service is running")
|
||||||
|
os.Exit(0)
|
||||||
case service.StatusStopped:
|
case service.StatusStopped:
|
||||||
stdoutMsg("Service is stopped")
|
stdoutMsg("Service is stopped")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -309,7 +313,7 @@ func initCLI() {
|
|||||||
uninstallCmd := &cobra.Command{
|
uninstallCmd := &cobra.Command{
|
||||||
PreRun: checkHasElevatedPrivilege,
|
PreRun: checkHasElevatedPrivilege,
|
||||||
Use: "uninstall",
|
Use: "uninstall",
|
||||||
Short: "Uninstall the ctrld service",
|
Short: "Stop and uninstall the ctrld service",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
prog := &prog{}
|
prog := &prog{}
|
||||||
|
|||||||
Reference in New Issue
Block a user