Skip to content

Commit

Permalink
fix(cmd): tty should auto disable color for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Arqu committed Apr 14, 2020
1 parent c3b616a commit abf678d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions cmd/qri.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/rpc"
"os"
"runtime"
"sync"

"github.com/qri-io/ioes"
Expand All @@ -17,17 +18,33 @@ import (

// NewQriCommand represents the base command when called without any subcommands
func NewQriCommand(ctx context.Context, pf PathFactory, generator gen.CryptoGenerator, ioStreams ioes.IOStreams) *cobra.Command {

qriPath, ipfsPath := pf()
opt := NewQriOptions(ctx, qriPath, ipfsPath, generator, ioStreams)

cmd := &cobra.Command{
Use: "qri",
Short: "qri GDVCS CLI",
Long: `qri ("query") is a set of tools for building & sharing datasets: https://qri.io
Feedback, questions, bug reports, and contributions are welcome!
https://github.com/qri-io/qri/issues`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
noColor, err := cmd.Flags().GetBool("no-color")
if err == nil && noColor {
setNoColor(noColor)
shouldColorOutput := false
cfg := opt.Instance().Config()
if cfg != nil && cfg.CLI != nil {
shouldColorOutput = cfg.CLI.ColorizeOutput
}
// todo(arqu): have a config var to indicate force override for windows
if runtime.GOOS == "windows" {
shouldColorOutput = false
}
if cmd.Flags().Changed("no-color") {
noColor, err := cmd.Flags().GetBool("no-color")
if err == nil {
shouldColorOutput = !noColor
}
}
setNoColor(!shouldColorOutput)
noPrompt, err := cmd.Flags().GetBool("no-prompt")
if err == nil && noPrompt {
setNoPrompt(noPrompt)
Expand All @@ -36,9 +53,6 @@ https://github.com/qri-io/qri/issues`,
BashCompletionFunction: bashCompletionFunc,
}

qriPath, ipfsPath := pf()
opt := NewQriOptions(ctx, qriPath, ipfsPath, generator, ioStreams)

cmd.SetUsageTemplate(rootUsageTemplate)
cmd.PersistentFlags().BoolVarP(&opt.NoPrompt, "no-prompt", "", false, "disable all interactive prompts")
cmd.PersistentFlags().BoolVarP(&opt.NoColor, "no-color", "", false, "disable colorized output")
Expand Down

0 comments on commit abf678d

Please sign in to comment.