Add isStdinTerminal and isStdoutTerminal to NewCLI constructor #50
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.
This pull request introduces changes to the
internal/cli/cli.go
,internal/cli/cli_test.go
, andmain.go
files. The primary goal of these changes is to improve the handling of terminal-related functionalities in the command-line interface (CLI) of the application. This is achieved by adding new fields to theCLI
struct, modifying theNewCLI
function, and updating the related tests.Here are the key changes in order of importance:
Refactoring of the
CLI
struct andNewCLI
function:isStdinTerminal
andisStdoutTerminal
, were added to theCLI
struct to keep track of whether the standard input and output are terminal interfaces.NewCLI
function was updated to accept two new parameters corresponding to these new fields. This change was reflected in all the places whereNewCLI
was called [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13].Improved handling of color output:
color
field in theCLI
struct was renamed toisColor
for consistency.parseFlags
method was updated to use theisStdoutTerminal
field when determining whether to color the output.filterProcess
method was updated to use the newisColor
field instead of the oldcolor
field.Improved handling of terminal input:
parseFlags
andvalidateInput
methods were updated to use theisStdinTerminal
field when parsing flags and validating input [1] [2].Updated tests:
cli_test.go
file were updated to reflect the changes in theNewCLI
function and theCLI
struct [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11].Removal of unused imports:
golang.org/x/term
import was removed fromcli.go
as it is no longer needed after the refactoring.strings
import was added tocli_test.go
for the new tests.