diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-18 07:45:37 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-18 07:45:37 +0300 |
| commit | 4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b (patch) | |
| tree | 2dc708cbb95975d34084eb5afd376871caa13e27 /internal/askcli/dispatch.go | |
| parent | ece7dcfd232b780f5650326c8ac2379ca70387d4 (diff) | |
ik0 replace test seams with dependency injection
Diffstat (limited to 'internal/askcli/dispatch.go')
| -rw-r--r-- | internal/askcli/dispatch.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/internal/askcli/dispatch.go b/internal/askcli/dispatch.go index 924ca67..cdfc1d8 100644 --- a/internal/askcli/dispatch.go +++ b/internal/askcli/dispatch.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "time" ) // Runner performs CLI work that would otherwise be handled by the ask CLI itself. @@ -14,18 +15,30 @@ type Runner interface { } // Dispatcher translates CLI arguments into concrete subcommands and presents the output. +// +// newTicker is the injected factory for the watch-loop ticker. Production code +// uses the real time.Ticker-backed factory installed by NewDispatcher; tests +// inject a fake ticker so they can drive the watch loop without real delays. type Dispatcher struct { runner Runner jsonOutput bool + newTicker func(time.Duration) watchTicker + capture func(context.Context, []byte) (string, error) } -// NewDispatcher creates a Dispatcher backed by the provided Runner or a default executor when nil. +// NewDispatcher creates a Dispatcher backed by the provided Runner or a default +// executor when nil. It wires the default real-ticker factory used by the +// `ask watch` loop. func NewDispatcher(runner Runner) *Dispatcher { if runner == nil { e := NewExecutor("ask") runner = &e } - return &Dispatcher{runner: runner} + return &Dispatcher{ + runner: runner, + newTicker: newRealWatchTicker, + capture: editorCapture, + } } func parseGlobalFlags(args []string) ([]string, bool) { |
