Skip to content

feat(output)!: put the product on stdout and the narration on stderr - #122

Open
Ilyes512 wants to merge 2 commits into
mainfrom
feat/output-stdout-product
Open

feat(output)!: put the product on stdout and the narration on stderr#122
Ilyes512 wants to merge 2 commits into
mainfrom
feat/output-stdout-product

Conversation

@Ilyes512

Copy link
Copy Markdown
Member

Summary

  • Info moves to stderr in both writers; a new Writer.WriteResult(record, format, args...) carries the single-line product on stdout (pretty renders the sentence, JSON marshals the record).
  • Re-classified the call sites that are answers: version{"version":"…"}, template validate{"valid":true|false} on both paths, template list writes an empty table ([]) when nothing is registered, template update answers with a Name/Status/Latest table instead of sentences.
  • Every other Info call site is narration and follows Info to stderr; fmt.Fprint added to the errcheck exclusions.
  • Golden tests now assert the corrected stream per method (existing bytes unchanged, four new files), plus executeCmdStreams in internal/cmd for stream-level assertions.
  • The output contract moves to docs/content/docs/architecture/output.md, which replaces the Info → stdout rows in overview.md; README and the commands pages document how to script against stdout.

Note: template update with nothing checkable now prints an empty table plus a hint on stderr, where it previously printed nothing.

Closes #113

Info wrote to stdout in both writers while Warn/Error/WriteErr already went to
stderr, so narration landed in the data stream: `specs template list -o json`
emitted an info object between the records, and `specs version -o json` answered
with an English sentence rather than a field.

Info now writes to stderr, and a WriteResult(record, format, args...) method
carries the single-line product a command answers with — pretty renders the
sentence, JSON marshals the record, so every stdout line stays a typed object.

Re-classified the call sites that are answers rather than narration:

- `version` reports {"version": "..."}; $(specs version) is unchanged.
- `template validate` reports {"valid": true|false} on both paths.
- `template list` writes an empty table when nothing is registered, so the empty
  answer has the shape of the non-empty one, and narrates the hint on stderr.
- `template update` answers with a Name/Status/Latest table instead of
  sentences, sharing the error-kind labels with `template list`.

Every other Info call site is narration and simply follows Info to stderr.

Refs #113
overview.md documented the old behaviour (`Info` → stdout) in three table rows,
which is too little room for a rule the whole command tree has to follow. The
contract, the Writer interface, the colour decision and the golden-file tests
move to docs/content/docs/architecture/output.md, including guidance on which
method a new call site needs; overview.md keeps a summary and a pointer.

Also documents the split for users: how to script against stdout in README.md
and the commands pages, and what `template update` now answers with.

Refs #113
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

output: Info writes to stdout — stdout should carry the product, stderr the narration

1 participant