For plugins, only enable color output if command is running in a terminal #1015
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.
Reviewers
r? @
cc @stripe/developer-products
Summary
This PR changes the plugin interface so that the host tells the plugin process if the host's stdin/out/err are terminals or not. Plugins can read this this to decide if they should print color output. In addition, this opens up the possibility of adding other terminal-only features, evolving the plugin interface, and separating concerns between host and plugin.
This change is needed because functions like
term.IsTerminal
always return false when called inside the plugin due to how the plugin's file descriptors are managed by the host process.To change the interface, we leverage the go-plugin package's versioning ability to implement a "major change" to the plugin interface. The old interface is defined as:
while the new interface is defined as:
This new interface uses gRPC instead of net/rpc to handle IPC between the host and plugin. gRPC is needed because the net/rpc implementation can't handle serializing complex data structures, which we've introduced in a struct called
AdditionalInfo
.This change is backwards compatible because the go-plugin library automatically handles version negotiation. Although the new interface is backwards incompatible, we keep the old interface around so older clients can continue to request the old interface.