ipfs / ipfs/go-ipfs-cmds

PostRun is an awkward fit for CLI output

Open
#115 2 comments 0 reactions 1 assignee Claimed by @Stebalien View on GitHub
kind/enhancement
Dominant language
Go
Stars
52
Forks
45
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.