Skip to content

Commit

Permalink
Added option to override gauntlet command and use yarn (smartcontract…
Browse files Browse the repository at this point in the history
…kit#476)

* Added support to run yarn commands
  • Loading branch information
smickovskid authored Nov 2, 2022
1 parent 8a47dcc commit 7edcf63
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions gauntlet/gauntlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
// Gauntlet contains helpful data to run gauntlet commands
type Gauntlet struct {
exec string
Command string
Network string
NetworkConfig map[string]string
}
Expand All @@ -37,6 +38,7 @@ func NewGauntlet() (*Gauntlet, error) {
os.Setenv("SKIP_PROMPTS", "true")
g := &Gauntlet{
exec: yarn,
Command: "gauntlet", // Setting gauntlet as the default command
NetworkConfig: make(map[string]string),
}
g.GenerateRandomNetwork()
Expand Down Expand Up @@ -67,14 +69,20 @@ type ExecCommandOptions struct {
RetryDelay time.Duration
}

// ExecCommand Executes a gauntlet command with the provided arguments.
// ExecCommand Executes a gauntlet or yarn command with the provided arguments.
//
// It will also check for any errors you specify in the output via the errHandling slice.
func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (string, error) {
output := ""
// append gauntlet and network to args since it is always needed
updatedArgs := append([]string{"gauntlet"}, args...)
updatedArgs = insertArg(updatedArgs, 2, g.Flag("network", g.Network))
var updatedArgs []string
if g.Command == "gauntlet" {
updatedArgs = append([]string{g.Command}, args...)
// Appending network to the gauntlet command
updatedArgs = insertArg(updatedArgs, 2, g.Flag("network", g.Network))
} else {
updatedArgs = args
}

printArgs(updatedArgs)

cmd := exec.Command(g.exec, updatedArgs...) // #nosec G204
Expand All @@ -90,7 +98,7 @@ func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (strin
reader := bufio.NewReader(stdout)
line, err := reader.ReadString('\n')
for err == nil {
log.Info().Str("stdout", line).Msg("Gauntlet")
log.Info().Str("stdout", line).Msg(g.Command)
output = fmt.Sprintf("%s%s", output, line)
if options.CheckErrorsInRead {
rerr := checkForErrors(options.ErrHandling, output)
Expand All @@ -104,7 +112,7 @@ func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (strin
reader = bufio.NewReader(stderr)
line, err = reader.ReadString('\n')
for err == nil {
log.Info().Str("stderr", line).Msg("Gauntlet")
log.Info().Str("stderr", line).Msg(g.Command)
output = fmt.Sprintf("%s%s", output, line)
if options.CheckErrorsInRead {
rerr := checkForErrors(options.ErrHandling, output)
Expand All @@ -127,7 +135,7 @@ func (g *Gauntlet) ExecCommand(args []string, options ExecCommandOptions) (strin
// catch any exit codes
err = cmd.Wait()

log.Debug().Msg("Gauntlet command Completed")
log.Debug().Str("Command", g.Command).Msg("command Completed")
return output, err
}

Expand Down

0 comments on commit 7edcf63

Please sign in to comment.