Skip to content

Commit 97ee30c

Browse files
author
Nicolas Sterchele
authored
Merge pull request #9 from peopledoc/fix/exit-status
Make jarvis POSIX compliant by returning an exit status
2 parents e98b42d + 2bb51a7 commit 97ee30c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

cmd/root.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
const SilenceUsageOnError = true
15+
const SilenceErrors = true
1516

1617
var (
1718
configFile string
@@ -20,9 +21,10 @@ var (
2021
isDebug bool
2122

2223
rootCmd = &cobra.Command{
23-
Use: "jarvis",
24-
SilenceUsage: SilenceUsageOnError,
25-
Short: "jarvis is our automation CLI",
24+
Use: "jarvis",
25+
SilenceUsage: SilenceUsageOnError,
26+
SilenceErrors: SilenceErrors,
27+
Short: "jarvis is our automation CLI",
2628
Long: `jarvis is the main command, used to facilitate SRE's life.
2729
2830
jarvis is smart, jarvis is beautiful,

internal/pkg/command/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r Runner) Run(command string, params ...string) error {
3535
err := cmd.Start()
3636

3737
if err != nil {
38-
return fmt.Errorf("command: failed to start command:%v, err:%v", command, err)
38+
return fmt.Errorf("command: failed to start %v, err:%v", command, err)
3939
}
4040

4141
//To synchronize before calling Wait on cmd
@@ -59,7 +59,7 @@ func (r Runner) Run(command string, params ...string) error {
5959
err = cmd.Wait()
6060

6161
if err != nil {
62-
return fmt.Errorf("command: failed to run command:%v, err:%v", command, err)
62+
return fmt.Errorf("command: failed to run %v, err:%v", command, err)
6363
}
6464
if errStdout != nil || errStderr != nil {
6565
return fmt.Errorf("command: failed to capture stdout or stderr")

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package main
22

33
import (
4+
"fmt"
45
"jarvis/cmd"
6+
"os"
57
)
68

79
func main() {
8-
cmd.Execute()
10+
if err := cmd.Execute(); err != nil {
11+
fmt.Fprintf(os.Stderr, "%v\n", err)
12+
os.Exit(1)
13+
}
914
}

0 commit comments

Comments
 (0)