Skip to content

PostRun is an awkward fit for CLI output #115

Open
@Stebalien

Description

@Stebalien

When writing CLI output, we often want to write to stdout/stderr, sometimes even controlling terminal output. For commands that just need to format to stdout, we can use a text marshaler. However, for commands that need to write to some parts to stderr and/or control the terminal, that doesn't really fit.

So, in practice, we use a PostRun function. However, that isn't a fit either as it expects us to transform a response emitter.

Currently, we just hack it by writing to stdout/stderr anyways but I'd like a better option.


So, I'd like to:

  1. Deprecate PostRun. If you look at how we use it, we don't actually use it to transform one response emitter into another, we use it to write to the console. We could keep it, but, IMO, the current form doesn't fit very well. I can't think of a case where I'd want to transform the results based on the output mode.
  2. Encourage using Encoders when we don't need anything fancy (just text and a terminal error).
  3. Provide a DisplayCLI field that takes a func(res cmds.Response, stdout, stderr io.Writer) error.

In the future, we could add additional display functions for different interfaces (e.g., browsers) but this seems like a good starting point. Thoughts?

Metadata

Metadata

Assignees

Labels

kind/enhancementA net-new feature or improvement to an existing feature

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions