Skip to content

feat(cli/cliui): add TextFormatFunc and OutputFormatter.WriteLine helpers - #30508

Merged
nickvigilante merged 2 commits into
mainfrom
vigilante/cli-56-cliui-add-shared-text-formatter-and-write-helpers-for-o
Oct 8, 2026
Merged

nickvigilante merged 2 commits into
mainfrom
vigilante/cli-56-cliui-add-shared-text-formatter-and-write-helpers-for-o

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Adds two small helpers to cli/cliui/output.go so commands that add -o/--output don't repeat the same boilerplate, as suggested in #30152 (comment) by @jeremyruppel.

  • TextFormatFunc[T] wraps ChangeFormatterData(TextFormat(), ...) with the type assertion and "expected X, got Y" error, so a command only supplies its render function.
  • (*OutputFormatter).WriteLine formats data and writes it to an io.Writer with a trailing newline, replacing the Format + Fprintln block.

No existing callers change in this PR. These PRs are stacked on it and use the helpers:

Migrating the existing callers on main (for example cli/organization.go, enterprise/cli/workspaceproxy.go) is left for a follow-up, since some of them print with Fprint rather than Fprintln and need care to keep output identical.

Refs CLI-56

Decision log
  • A global -o flag on the root command was ruled out because coder config-ssh already uses -o for --ssh-option.
  • The "one-time secret plus metadata" response structs in feat: add JSON output to coder tokens create #30135 and feat: add JSON output to coder provisioner keys create #30152 stay local to each command, since they embed different SDK types and a shared helper would save little.
  • WriteLine uses Fprintln to match the four stacked PRs and most existing callers.
    It was renamed from Write during review so the trailing newline is visible at call sites and the method is not confused with io.Writer.

Note

This PR was generated by Coder Agents on behalf of @nickvigilante.

Commands adding -o/--output repeat the same type-assertion wrapper around
ChangeFormatterData(TextFormat(), ...) and the same format-then-Fprintln
block. These helpers let each command express only its rendering logic.

Refs CLI-56
@linear-code

linear-code Bot commented Oct 8, 2026

Copy link
Copy Markdown

CLI-56

@jeremyruppel jeremyruppel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few non-blocking notes.

Note

This review was generated by Coder Agents on behalf of @jeremyruppel.

Comment thread cli/cliui/output.go Resolved
Comment thread cli/cliui/output.go Resolved
Comment thread cli/cliui/output.go Resolved
Comment thread cli/cliui/output.go Resolved
… names

WriteLine makes the trailing newline visible at call sites and avoids
confusion with io.Writer. TextFormatFunc now names the expected type with
reflect.TypeFor, since %T on a nil interface value prints <nil>.
@nickvigilante nickvigilante changed the title feat(cli/cliui): add TextFormatFunc and OutputFormatter.Write helpers feat(cli/cliui): add TextFormatFunc and OutputFormatter.WriteLine helpers Oct 8, 2026

@jeremyruppel jeremyruppel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this rules. thanks for extracting this into a helper, I think we'll get some mileage out of it 🚗

@nickvigilante
nickvigilante enabled auto-merge (squash) October 8, 2026 18:41
@nickvigilante
nickvigilante merged commit 0efb574 into main Oct 8, 2026
37 checks passed
@nickvigilante
nickvigilante deleted the vigilante/cli-56-cliui-add-shared-text-formatter-and-write-helpers-for-o branch October 8, 2026 19:41
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants