From 4a3cbd4614373ac8bb96e71d0dd5fb7d705cea79 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 16 Oct 2026 08:22:35 -0600 Subject: [PATCH] refactor(status): share CLI status reporter constructor Add status.NewCLIReporter/CLIOptions in pkg/status so the four CLI newStatusReporter constructors (ci, config apply, provider status, workspace up status) share one wrapper around NewReporter and ForPipeline. Output, labels, envelopes and error returns are unchanged. --- cmd/ci/status.go | 16 ++++++---------- cmd/config/apply.go | 16 ++++++---------- cmd/provider/status.go | 18 +++++++----------- cmd/workspace/up/status.go | 18 +++++++----------- pkg/status/render.go | 30 ++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 42 deletions(-) diff --git a/cmd/ci/status.go b/cmd/ci/status.go index 75e35600df..269885d5cf 100644 --- a/cmd/ci/status.go +++ b/cmd/ci/status.go @@ -7,12 +7,12 @@ import ( ) func newStatusReporter(out io.Writer, verbose bool) (status.Reporter, error) { - reporter, err := status.NewReporter(status.ReporterOptions{ - Format: "plain", - Out: out, - Prefix: "ci", - Verbose: verbose, - SuppressFailureDetails: true, + return status.NewCLIReporter(status.CLIOptions{ + Format: "plain", + Out: out, + Prefix: "ci", + Verbose: verbose, + Pipeline: status.PipelineWorkspaceUp, Labels: map[status.Phase]string{ status.PhaseCloningRepository: "cloning repository", status.PhaseResolvingConfig: "resolving devcontainer config", @@ -29,8 +29,4 @@ func newStatusReporter(out io.Writer, verbose bool) (status.Reporter, error) { }, Envelope: func(status.Event) error { return nil }, }) - if err != nil { - return nil, err - } - return status.ForPipeline(reporter, status.PipelineWorkspaceUp), nil } diff --git a/cmd/config/apply.go b/cmd/config/apply.go index a0b716bb3c..3b3221bbfd 100644 --- a/cmd/config/apply.go +++ b/cmd/config/apply.go @@ -173,12 +173,12 @@ func (cmd *ApplyCmd) prepareContainer( } func newStatusReporter(resultFormat string, out io.Writer, verbose bool) (status.Reporter, error) { - reporter, err := status.NewReporter(status.ReporterOptions{ - Format: resultFormat, - Out: out, - Prefix: "config", - Verbose: verbose, - SuppressFailureDetails: true, + return status.NewCLIReporter(status.CLIOptions{ + Format: resultFormat, + Out: out, + Prefix: "config", + Verbose: verbose, + Pipeline: status.PipelineWorkspaceUp, Labels: map[status.Phase]string{ status.PhaseResolvingConfig: "resolving devcontainer config", status.PhaseRunningLifecycleHook: "applying lifecycle configuration", @@ -188,10 +188,6 @@ func newStatusReporter(resultFormat string, out io.Writer, verbose bool) (status return devcconfig.WriteStatusJSON(out, e) }, }) - if err != nil { - return nil, err - } - return status.ForPipeline(reporter, status.PipelineWorkspaceUp), nil } func (cmd *ApplyCmd) resolveDockerPath() string { diff --git a/cmd/provider/status.go b/cmd/provider/status.go index 2726937611..25f699e9a1 100644 --- a/cmd/provider/status.go +++ b/cmd/provider/status.go @@ -16,21 +16,17 @@ func newStatusReporter( verbose ...bool, ) (status.Reporter, error) { showDurations := len(verbose) > 0 && verbose[0] - r, err := status.NewReporter(status.ReporterOptions{ - Format: resultFormat, - Out: out, - Prefix: "provider", - Labels: phaseLabels, - Verbose: showDurations, - SuppressFailureDetails: true, + return status.NewCLIReporter(status.CLIOptions{ + Format: resultFormat, + Out: out, + Prefix: "provider", + Verbose: showDurations, + Pipeline: status.PipelineProvider, + Labels: phaseLabels, Envelope: func(e status.Event) error { return config2.WriteStatusJSON(out, e) }, }) - if err != nil { - return nil, err - } - return status.ForPipeline(r, status.PipelineProvider), nil } var phaseLabels = map[status.Phase]string{ diff --git a/cmd/workspace/up/status.go b/cmd/workspace/up/status.go index e34b32694b..b19b1f593c 100644 --- a/cmd/workspace/up/status.go +++ b/cmd/workspace/up/status.go @@ -14,21 +14,17 @@ func newStatusReporter( verbose ...bool, ) (status.Reporter, error) { showDurations := len(verbose) > 0 && verbose[0] - r, err := status.NewReporter(status.ReporterOptions{ - Format: resultFormat, - Out: out, - Prefix: "up", - Labels: phaseLabels, - Verbose: showDurations, - SuppressFailureDetails: true, + return status.NewCLIReporter(status.CLIOptions{ + Format: resultFormat, + Out: out, + Prefix: "up", + Verbose: showDurations, + Pipeline: status.PipelineWorkspaceUp, + Labels: phaseLabels, Envelope: func(e status.Event) error { return config2.WriteStatusJSON(out, e) }, }) - if err != nil { - return nil, err - } - return status.ForPipeline(r, status.PipelineWorkspaceUp), nil } var phaseLabels = map[status.Phase]string{ diff --git a/pkg/status/render.go b/pkg/status/render.go index abb1528b52..42ef11ce1e 100644 --- a/pkg/status/render.go +++ b/pkg/status/render.go @@ -37,6 +37,36 @@ func NewReporter(opts ReporterOptions) (Reporter, error) { return newReporter(resolveFormat(opts), opts) } +// CLIOptions configures the progress reporter for a CLI command. +type CLIOptions struct { + Format string + Out io.Writer + Prefix string + Pipeline Pipeline + Labels map[Phase]string + Envelope func(Event) error + Verbose bool +} + +// NewCLIReporter builds the progress reporter for CLI commands: NewReporter +// with failure details left to the command boundary, and every event stamped +// with o.Pipeline. +func NewCLIReporter(o CLIOptions) (Reporter, error) { + r, err := NewReporter(ReporterOptions{ + Format: o.Format, + Out: o.Out, + Prefix: o.Prefix, + Labels: o.Labels, + Envelope: o.Envelope, + Verbose: o.Verbose, + SuppressFailureDetails: true, + }) + if err != nil { + return nil, err + } + return ForPipeline(r, o.Pipeline), nil +} + func resolveFormat(opts ReporterOptions) string { format := opts.Format if format == "" {