From eb9d5f861a7b46a1827c2caa6abbfb8d77e29ffb Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 23 Mar 2024 14:50:37 +0100 Subject: chore(promises): make a Status function part of the Promise interface --- pkg/commands.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'pkg/commands.go') diff --git a/pkg/commands.go b/pkg/commands.go index b5a11ca..df42919 100644 --- a/pkg/commands.go +++ b/pkg/commands.go @@ -26,7 +26,7 @@ func CommandWithEnv(env []string, cmd string, args ...string) *CommandPromise { cmd: cmd, env: env, err: nil, - Status: PROMISED, + status: PROMISED, } } @@ -36,7 +36,7 @@ type CommandPromise struct { cmd string env []string err error - Status Status + status Status Stdout bytes.Buffer Stderr bytes.Buffer } @@ -60,16 +60,16 @@ func (c *CommandPromise) Resolve() { cmd.Stderr = &c.Stderr if c.err = cmd.Run(); c.err != nil { - c.Status = BROKEN + c.status = BROKEN slog.Error("command", "args", c.args, "cmd", c.cmd, "env", c.env, "err", c.err, "stdout", c.Stdout.String(), "stderr", c.Stderr.String(), "status", c.Status) return } if c.Stdout.Len() == 0 && c.Stderr.Len() > 0 { - c.Status = BROKEN + c.status = BROKEN slog.Error("command", "args", c.args, "cmd", c.cmd, "env", c.env, "stdout", c.Stdout.String(), "stderr", c.Stderr.String(), "status", c.Status) return } - c.Status = REPAIRED + c.status = REPAIRED slog.Info("command", "args", c.args, "cmd", c.cmd, "env", c.env, "stderr", c.Stderr.String(), "status", c.Status) // TODO add a notion of repaired? for _, p := range c.chain { @@ -77,13 +77,17 @@ func (c *CommandPromise) Resolve() { } } +func (c CommandPromise) Status() Status { + return c.status +} + // ----- Internal -------------------------------------------------------------- func resolveCommands() (status Status) { status = KEPT for _, c := range commands { - if c.Status == PROMISED { + if c.status == PROMISED { c.Resolve() - switch c.Status { + switch c.status { case BROKEN: return BROKEN case REPAIRED: -- cgit v1.2.3