diff --git a/cmd/cmd_run.go b/cmd/cmd_run.go index 994dd6a..8113e99 100644 --- a/cmd/cmd_run.go +++ b/cmd/cmd_run.go @@ -23,13 +23,16 @@ func NewRunCmd() *cobra.Command { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + defer func() { + os.Exit(cmd.ProcessState.ExitCode()) + }() + m := marker.NewNotificationMarker(cmd) defer m.Done() err := cmd.Run() if err != nil { - fmt.Printf("Error: %s\n", err.Error()) - os.Exit(1) + fmt.Printf("n-cli run error: %s\n", err.Error()) } }, } diff --git a/pkg/notifier/marker/marker.go b/pkg/notifier/marker/marker.go index 5fca70f..3aa6a25 100644 --- a/pkg/notifier/marker/marker.go +++ b/pkg/notifier/marker/marker.go @@ -28,12 +28,18 @@ func NewNotificationMarker(cmd *exec.Cmd) NotificationMarker { func (m *NotificationMarkerImpl) Done() { elapsed := time.Since(m.StartedFrom) // elapsedMs := elapsed.Milliseconds() + prettyCommand := strings.Join(m.Command.Args, " ") - if m.Command.ProcessState.ExitCode() < 0 { + exitCode := m.Command.ProcessState.ExitCode() + msg := "" + if exitCode < 0 { return + } else if exitCode == 0 { + msg = fmt.Sprintf("Command `%s` COMPLETE. Elapsed: %s", prettyCommand, elapsed.String()) + } else { + msg = fmt.Sprintf("Command `%s` FAILED. Status=%d. Elapsed: %s", prettyCommand, exitCode, elapsed.String()) } - msg := fmt.Sprintf("Command `%s` is complete. Elapsed: %s", strings.Join(m.Command.Args, " "), elapsed.String()) err := notifier.Notify(msg) if err != nil { fmt.Printf("Error encountered when sending notification: %s\n", err.Error())