all repos — erl @ ad8f97f9fb886a7c2e7ef7ef8a738ae7f0c9ddf5

Execute Reload Loop

feat: add quiet flag

Alan Pearce
commit

ad8f97f9fb886a7c2e7ef7ef8a738ae7f0c9ddf5

parent

921c8f0ae3eec6acf4f3cfb236f3a7f0869006e9

1 file changed, 14 insertions(+), 14 deletions(-)

changed files
M command/command.gocommand/command.go
@@ -9,7 +9,7 @@ "os/exec"
"strings" "time" - "github.com/fatih/color" + "alin.ovh/erl/output" ) type Command interface {
@@ -24,14 +24,13 @@
name string args []string - opts Options + out output.Output - printFail func(string, ...any) - printInfo func(string, ...any) - printSuccess func(string, ...any) + opts Options } type Options struct { + Output io.Writer Stdout io.Writer Stderr io.Writer }
@@ -45,15 +44,16 @@ }
if options.Stderr == nil { options.Stderr = os.Stderr } + if options.Output == nil { + options.Output = os.Stderr + } return &Cmd{ name: name, args: args, opts: options, - printFail: color.New(color.FgRed).PrintfFunc(), - printInfo: color.New().PrintfFunc(), - printSuccess: color.New(color.FgGreen).PrintfFunc(), + out: output.New(options.Output), } }
@@ -65,11 +65,11 @@ return fmt.Errorf("error killing command: %v", err)
} if cmd.ProcessState == nil { - cmd.printInfo("[command not stopped, waiting %s seconds before killing]\n", timeout) + cmd.out.Info("[command not stopped, waiting %s seconds before killing]\n", timeout) time.Sleep(timeout) if cmd.ProcessState == nil { - cmd.printInfo("[command not stopped, killing]\n") + cmd.out.Info("[command not stopped, killing]\n") err := cmd.Process.Kill() if err != nil { return fmt.Errorf("error killing command: %v", err)
@@ -91,9 +91,9 @@ if err != nil {
var exitErr *exec.ExitError if errors.As(err, &exitErr) { if cmd.Exited() { - cmd.printFail("[command exited with code %d]\n", cmd.ProcessState.ExitCode()) + cmd.out.Fail("[command exited with code %d]\n", cmd.ProcessState.ExitCode()) } else { - cmd.printFail("[command stopped]\n") + cmd.out.Fail("[command stopped]\n") } } else { return fmt.Errorf("error waiting for command: %v", err)
@@ -101,7 +101,7 @@ }
} if cmd.Exited() && cmd.ProcessState.Success() { - cmd.printSuccess("[command finished]\n") + cmd.out.Success("[command finished]\n") } return nil
@@ -109,7 +109,7 @@ }
func (cmd *Cmd) Start() error { cmd.makeCommand() - cmd.printSuccess("[running: %s %s]\n", cmd.name, strings.Join(cmd.args, " ")) + cmd.out.Success("[running: %s %s]\n", cmd.name, strings.Join(cmd.args, " ")) err := cmd.Cmd.Start() if err != nil { return fmt.Errorf("error starting command: %v", err)