diff options
author | Julien Dessaux | 2024-03-23 14:50:37 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-24 09:58:15 +0100 |
commit | eb9d5f861a7b46a1827c2caa6abbfb8d77e29ffb (patch) | |
tree | b7d8bfca9d583fb6a555a73cda36d0c940dd692e /pkg/commands.go | |
parent | feat(custom): implemented custom promises (diff) | |
download | gonf-eb9d5f861a7b46a1827c2caa6abbfb8d77e29ffb.tar.gz gonf-eb9d5f861a7b46a1827c2caa6abbfb8d77e29ffb.tar.bz2 gonf-eb9d5f861a7b46a1827c2caa6abbfb8d77e29ffb.zip |
chore(promises): make a Status function part of the Promise interface
Diffstat (limited to '')
-rw-r--r-- | pkg/commands.go | 18 |
1 files changed, 11 insertions, 7 deletions
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: |