| 1 | package legatus |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "go.bigb.es/auxilia/culpa" |
| 7 | ) |
| 8 | |
| 9 | // ErrNoPrompter is returned by the non-interactive default prompter when a step |
| 10 | // requires a choice it cannot answer. |
| 11 | var ErrNoPrompter = culpa.WithCode(culpa.New("legatus: no interactive prompter configured"), "LEGATUS_NO_PROMPTER") |
| 12 | |
| 13 | // Reporter receives engine-driven progress events for human-facing output. It is |
| 14 | // decoupled from structured logging; the engine drives both with no step |
| 15 | // involvement (PC5). |
| 16 | type Reporter interface { |
| 17 | FlowStart(host, flow string) |
| 18 | StepStart(host, step string) |
| 19 | StepDone(host string, r StepResult) |
| 20 | FlowDone(host string, r FlowResult) |
| 21 | RunDone(r RunResult) |
| 22 | } |
| 23 | |
| 24 | // Prompter answers interactive questions a step may ask. The core is |
| 25 | // non-interactive by default (PC2); a real prompter is injected by the caller. |
| 26 | type Prompter interface { |
| 27 | Confirm(ctx context.Context, question string) (bool, error) |
| 28 | Select(ctx context.Context, question string, options []string) (int, error) |
| 29 | } |
| 30 | |
| 31 | // NopReporter discards all events. It is the default reporter. |
| 32 | type NopReporter struct{} |
| 33 | |
| 34 | func (NopReporter) FlowStart(string, string) {} |
| 35 | func (NopReporter) StepStart(string, string) {} |
| 36 | func (NopReporter) StepDone(string, StepResult) {} |
| 37 | func (NopReporter) FlowDone(string, FlowResult) {} |
| 38 | func (NopReporter) RunDone(RunResult) {} |
| 39 | |
| 40 | // DenyPrompter is the non-interactive default: it declines confirmations and |
| 41 | // errors on selections. |
| 42 | type DenyPrompter struct{} |
| 43 | |
| 44 | func (DenyPrompter) Confirm(context.Context, string) (bool, error) { return false, nil } |
| 45 | |
| 46 | func (DenyPrompter) Select(context.Context, string, []string) (int, error) { |
| 47 | return -1, ErrNoPrompter |
| 48 | } |
| 49 | |