Repository navigation
refactor: write output and diagnostics to the streams passed to Run - #477
Merged
Merged
Conversation
thde
force-pushed
the
refactor/io-streams
branch
from
October 15, 2026 13:08
15cbc46 to
67946f3
Compare
thde
force-pushed
the
refactor/io-streams
branch
from
October 15, 2026 13:24
67946f3 to
1dfee6f
Compare
format.Writer takes the output and diagnostics writers from Kong's context, and Err returns the latter. Commands write the image pull progress, subprocess errors, build log errors and repository check messages to it instead of os.Stderr, so all output of a command goes to the writers main passes to Run. Kong's writers replace the io.Writer binding, so stdout and stderr have a single source, also in the test harnesses.
thde
force-pushed
the
refactor/io-streams
branch
from
October 16, 2026 08:15
1dfee6f to
0554590
Compare
format.IOStreams holds the input, output and error of a command. newParser binds it for the BeforeApply hooks of format.Writer and format.Reader and makes its writers those of Kong, so stdout, stderr and stdin come from the streams passed to Run. The hooks take the streams instead of the Kong context and the bound io.Reader, so format no longer imports Kong and commands initialize Writer and Reader from a single value. testutil.KongStreams replaces testutil.KongContext, which built Kong's internal structs by hand, and binds the streams for test parsers as newParser does. Tests parsing structs without hooks drop the writers they never used.
The database exec commands give their subprocess the command's streams and check the command's stdin for a terminal, instead of the process's. exec app takes the bound IOStreams. main gets the streams from dockerterm.StdStreams, so on Windows every command now runs with the console's virtual terminal mode enabled.
NewWriter takes the writer for diagnostics next to the output, so a Writer built by hand no longer discards them silently. The IO wiring test finds the streams of a Writer and Reader by name rather than by position, and waitForBuildFinish takes its writer right after the context.
Warnings, spinners and confirmation prompts go to stderr instead of stdout, so they no longer corrupt the output of a command, such as the JSON of nctl get all -o json, and a prompt still shows when stdout is redirected. Run prints our own errors, the not-logged-in hint and the missing-command hint to stderr too. Like Kong on a parse error, the usage stays on stdout. Scripts reading warnings or errors from stdout need to read stderr instead.
thde
force-pushed
the
refactor/io-streams
branch
from
October 16, 2026 13:12
0554590 to
60415b5
Compare
SaadAssaf
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cmd.Runalready took stdin, stdout and stderr, but commands didn't use them consistently. Some wrote toos.Stderrdirectly. Warnings, spinners and prompts were mixed into stdout, which broke the JSON fromnctl get all -o jsonand hid prompts when stdout was redirected. Exec subprocesses checked the process's stdin for a terminal instead of the command's. The streams were also bound as a looseio.Writerandio.Readernext to Kong's own writers, so stdout had two sources and a hook couldn't tell which stream it had been given.This PR introduces a single value that carries a command's streams (a pattern also used by
kubectl):Runbuilds it once andnewParserbinds it for theBeforeApplyhooks offormat.Writerandformat.Reader. It also makes those streams Kong's writers, so help text, parse errors and command output share one source.formatno longer imports Kong.WritergainsErr()for diagnostics andOut()/In()for the raw streams, so terminal detection and subprocess inheritance keep working. In tests,testutil.KongStreamsreplaces the hand-builtKongContext.Behaviour changes
Warnings, spinners, confirmation prompts and
Run's own errors now go to stderr, and usage output stays on stdout. Scripts that read warnings or errors from stdout need to read stderr instead.mainnow gets its streams frommoby/term.StdStreams(), so on Windows every command runs with virtual terminal sequences enabled.