Handle the --color flag via proper global state
Use `color.NoColor` as a global progressively modified as one descends
down command flags. Allows non-surprising operation when --color is
accepted at multiple layers, and even makes this behave predictably:
lotus-miner --color actor control list --color=false
This commit is contained in:
+10
@@ -3,10 +3,13 @@ package cli
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/hako/durafmt"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/mattn/go-isatty"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
@@ -15,6 +18,13 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
// Set the global default, to be overridden by individual cli flags in order
|
||||
func init() {
|
||||
color.NoColor = os.Getenv("GOLOG_LOG_FMT") != "color" &&
|
||||
!isatty.IsTerminal(os.Stdout.Fd()) &&
|
||||
!isatty.IsCygwinTerminal(os.Stdout.Fd())
|
||||
}
|
||||
|
||||
func parseTipSet(ctx context.Context, api v0api.FullNode, vals []string) (*types.TipSet, error) {
|
||||
var headers []*types.BlockHeader
|
||||
for _, c := range vals {
|
||||
|
||||
Reference in New Issue
Block a user