Skip to content

feat: detect os.Stdin/os.Stdout redirection/pipe mode#994

Merged
MichaelMure merged 3 commits intomasterfrom
feat/detect-stdin-stdout-mode
Jan 17, 2023
Merged

feat: detect os.Stdin/os.Stdout redirection/pipe mode#994
MichaelMure merged 3 commits intomasterfrom
feat/detect-stdin-stdout-mode

Conversation

@smoyer64
Copy link
Collaborator

@smoyer64 smoyer64 commented Jan 16, 2023

In support of #831 and #993, this PR adds the ability to detect whether input is coming from the terminal or is being redirected/piped into the git-bug application as well as the corollary of output going to the terminal or being output to another application or file.

In general, there seem to be three categories of output for commands:

  1. Commands that have the same output regardless of how they're being used such as listing bugs in the JSON format.
  2. Commands that write the human readable portion of their output to os.StdErr and the machine-readable portion of their output to os.StdOut such as the output when creating a new bug (the id of the new bug should be written to StdOut and the " created" suffix should be written to StdErr.)
  3. Commands that need different behavior depending on whether the output is a terminal (presumably with a human watching) or to another application via redirection or piping (e.g. the adaptive terminal display with described in command: adapt the output of the bug list to the terminal size #993 where all line-oriented bug listings should be TSV if the output is redirected but should be prettier if shown to a user.)

All efforts should be made to create *nix friendly output using techniques 1 and 2 above - using TerminalIOMode and RedirectedOrPipedIOMode should be a last resort.

This PR also includes an equivalent feature for os.StdIn with the expectation that eventually commands such as bug new could read input from StdIn instead of an editor with the existing behavior for separating the title and description (comment index 0).

References #828.

@smoyer64 smoyer64 requested a review from MichaelMure January 16, 2023 16:17
@MichaelMure MichaelMure merged commit e689cc5 into master Jan 17, 2023
@MichaelMure MichaelMure deleted the feat/detect-stdin-stdout-mode branch January 17, 2023 19:14
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.

2 participants