Skip to content

Commit

Permalink
msg and exit code 1 on cli error
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Jul 20, 2023
1 parent c51b8a7 commit 32f5647
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/f1bonacc1/process-compose/src/client"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)

Expand All @@ -16,8 +15,7 @@ var listCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
processNames, err := client.GetProcessesName(pcAddress, port)
if err != nil {
log.Error().Msgf("Failed to get processes names %v", err)
return
logFatal(err, "failed to list processes")
}
for _, proc := range processNames {
fmt.Println(proc)
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ var restartCmd = &cobra.Command{
name := args[0]
err := client.RestartProcesses(pcAddress, port, name)
if err != nil {
log.Error().Msgf("Failed to restart processes %s: %v", name, err)
return
logFatal(err, "failed to restart process %s", name)
}
log.Info().Msgf("Process %s restarted", name)
},
Expand Down
21 changes: 2 additions & 19 deletions src/cmd/scale.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"github.com/f1bonacc1/process-compose/src/client"
"github.com/rs/zerolog/log"
"strconv"
Expand All @@ -21,29 +17,16 @@ var scaleCmd = &cobra.Command{
name := args[0]
count, err := strconv.Atoi(args[1])
if err != nil {
log.Error().Msgf("second argument must be an integer: %v", err)
return
logFatal(err, "second argument must be an integer")
}
err = client.ScaleProcess(pcAddress, port, name, count)
if err != nil {
log.Error().Msgf("Failed to scale processes %s: %v", name, err)
fmt.Println(err.Error())
return
logFatal(err, "failed to scale process %s", name)
}
log.Info().Msgf("Process %s scaled to %s", name, args[1])
},
}

func init() {
processCmd.AddCommand(scaleCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// scaleCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// scaleCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
3 changes: 1 addition & 2 deletions src/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ var startCmd = &cobra.Command{
name := args[0]
err := client.StartProcesses(pcAddress, port, name)
if err != nil {
log.Error().Msgf("Failed to start processes %s: %v", name, err)
return
logFatal(err, "failed to start process %s", name)
}
log.Info().Msgf("Process %s started", name)
},
Expand Down
6 changes: 1 addition & 5 deletions src/cmd/stop.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
Expand All @@ -18,8 +15,7 @@ var stopCmd = &cobra.Command{
name := args[0]
err := client.StopProcesses(pcAddress, port, name)
if err != nil {
log.Error().Msgf("Failed to stop processes %s: %v", name, err)
return
logFatal(err, "failed to stop process %s", name)
}
log.Info().Msgf("Process %s stopped", name)
},
Expand Down

0 comments on commit 32f5647

Please sign in to comment.