Skip to content

Commit

Permalink
🐛 Report command path without arguments and stdout/stderr on error.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Nov 21, 2023
1 parent e959196 commit 2df5558
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ package command
import (
"context"
"fmt"
hub "github.com/konveyor/tackle2-hub/addon"
"os/exec"
"strings"

hub "github.com/konveyor/tackle2-hub/addon"
)

var (
Expand Down Expand Up @@ -60,19 +61,28 @@ func (r *Command) RunWith(ctx context.Context) (err error) {

//
// RunSilent executes the command.
// Nothing reported in task Report.Activity.
// On error: The command (without arguments) and output are
// reported in task Report.Activity
func (r *Command) RunSilent() (err error) {
err = r.RunSilentWith(context.TODO())
return
}

//
// RunSilentWith executes the command with context.
// Nothing reported in task Report.Activity.
// On error: The command (without arguments) and output are
// reported in task Report.Activity
func (r *Command) RunSilentWith(ctx context.Context) (err error) {
cmd := exec.CommandContext(ctx, r.Path, r.Options...)
cmd.Dir = r.Dir
err = cmd.Run()
r.Output, err = cmd.CombinedOutput()
if err != nil {
addon.Activity(
"[CMD] %s failed: %s.\n%s",
r.Path,
err.Error(),
string(r.Output))
}
return
}

Expand Down

0 comments on commit 2df5558

Please sign in to comment.