Merge pull request #6743 from filecoin-project/chore/centralize_all_cli_color_handling

Handle the --color flag via proper global state
This commit is contained in:
Łukasz Magiera 2021-07-13 17:34:25 +02:00 committed by GitHub
commit dd09666399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 101 additions and 101 deletions

View File

@ -45,7 +45,6 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/tablewriter" "github.com/filecoin-project/lotus/lib/tablewriter"
) )
@ -1234,7 +1233,6 @@ var clientListRetrievalsCmd = &cli.Command{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Usage: "use color in display output", Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
@ -1252,6 +1250,10 @@ var clientListRetrievalsCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
@ -1260,7 +1262,6 @@ var clientListRetrievalsCmd = &cli.Command{
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
verbose := cctx.Bool("verbose") verbose := cctx.Bool("verbose")
color := cctx.Bool("color")
watch := cctx.Bool("watch") watch := cctx.Bool("watch")
showFailed := cctx.Bool("show-failed") showFailed := cctx.Bool("show-failed")
completed := cctx.Bool("completed") completed := cctx.Bool("completed")
@ -1280,7 +1281,7 @@ var clientListRetrievalsCmd = &cli.Command{
tm.Clear() tm.Clear()
tm.MoveCursor(1, 1) tm.MoveCursor(1, 1)
err = outputRetrievalDeals(ctx, tm.Screen, localDeals, verbose, color, showFailed, completed) err = outputRetrievalDeals(ctx, tm.Screen, localDeals, verbose, showFailed, completed)
if err != nil { if err != nil {
return err return err
} }
@ -1306,7 +1307,7 @@ var clientListRetrievalsCmd = &cli.Command{
} }
} }
return outputRetrievalDeals(ctx, cctx.App.Writer, localDeals, verbose, color, showFailed, completed) return outputRetrievalDeals(ctx, cctx.App.Writer, localDeals, verbose, showFailed, completed)
}, },
} }
@ -1314,7 +1315,7 @@ func isTerminalError(status retrievalmarket.DealStatus) bool {
// should patch this in go-fil-markets but to solve the problem immediate and not have buggy output // should patch this in go-fil-markets but to solve the problem immediate and not have buggy output
return retrievalmarket.IsTerminalError(status) || status == retrievalmarket.DealStatusErrored || status == retrievalmarket.DealStatusCancelled return retrievalmarket.IsTerminalError(status) || status == retrievalmarket.DealStatusErrored || status == retrievalmarket.DealStatusCancelled
} }
func outputRetrievalDeals(ctx context.Context, out io.Writer, localDeals []lapi.RetrievalInfo, verbose bool, color bool, showFailed bool, completed bool) error { func outputRetrievalDeals(ctx context.Context, out io.Writer, localDeals []lapi.RetrievalInfo, verbose bool, showFailed bool, completed bool) error {
var deals []api.RetrievalInfo var deals []api.RetrievalInfo
for _, deal := range localDeals { for _, deal := range localDeals {
if !showFailed && isTerminalError(deal.Status) { if !showFailed && isTerminalError(deal.Status) {
@ -1350,13 +1351,13 @@ func outputRetrievalDeals(ctx context.Context, out io.Writer, localDeals []lapi.
w := tablewriter.New(tableColumns...) w := tablewriter.New(tableColumns...)
for _, d := range deals { for _, d := range deals {
w.Write(toRetrievalOutput(d, color, verbose)) w.Write(toRetrievalOutput(d, verbose))
} }
return w.Flush(out) return w.Flush(out)
} }
func toRetrievalOutput(d api.RetrievalInfo, color bool, verbose bool) map[string]interface{} { func toRetrievalOutput(d api.RetrievalInfo, verbose bool) map[string]interface{} {
payloadCID := d.PayloadCID.String() payloadCID := d.PayloadCID.String()
provider := d.Provider.String() provider := d.Provider.String()
@ -1369,7 +1370,7 @@ func toRetrievalOutput(d api.RetrievalInfo, color bool, verbose bool) map[string
"PayloadCID": payloadCID, "PayloadCID": payloadCID,
"DealId": d.ID, "DealId": d.ID,
"Provider": provider, "Provider": provider,
"Status": retrievalStatusString(color, d.Status), "Status": retrievalStatusString(d.Status),
"PricePerByte": types.FIL(d.PricePerByte), "PricePerByte": types.FIL(d.PricePerByte),
"Received": units.BytesSize(float64(d.BytesReceived)), "Received": units.BytesSize(float64(d.BytesReceived)),
"TotalPaid": types.FIL(d.TotalPaid), "TotalPaid": types.FIL(d.TotalPaid),
@ -1399,19 +1400,17 @@ func toRetrievalOutput(d api.RetrievalInfo, color bool, verbose bool) map[string
return retrievalOutput return retrievalOutput
} }
func retrievalStatusString(c bool, status retrievalmarket.DealStatus) string { func retrievalStatusString(status retrievalmarket.DealStatus) string {
s := retrievalmarket.DealStatuses[status] s := retrievalmarket.DealStatuses[status]
if !c {
switch {
case isTerminalError(status):
return color.RedString(s)
case retrievalmarket.IsTerminalSuccess(status):
return color.GreenString(s)
default:
return s return s
} }
if isTerminalError(status) {
return color.RedString(s)
}
if retrievalmarket.IsTerminalSuccess(status) {
return color.GreenString(s)
}
return s
} }
var clientInspectDealCmd = &cli.Command{ var clientInspectDealCmd = &cli.Command{
@ -1808,7 +1807,6 @@ var clientListDeals = &cli.Command{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Usage: "use color in display output", Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
@ -1821,6 +1819,10 @@ var clientListDeals = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
@ -1829,7 +1831,6 @@ var clientListDeals = &cli.Command{
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
verbose := cctx.Bool("verbose") verbose := cctx.Bool("verbose")
color := cctx.Bool("color")
watch := cctx.Bool("watch") watch := cctx.Bool("watch")
showFailed := cctx.Bool("show-failed") showFailed := cctx.Bool("show-failed")
@ -1848,7 +1849,7 @@ var clientListDeals = &cli.Command{
tm.Clear() tm.Clear()
tm.MoveCursor(1, 1) tm.MoveCursor(1, 1)
err = outputStorageDeals(ctx, tm.Screen, api, localDeals, verbose, color, showFailed) err = outputStorageDeals(ctx, tm.Screen, api, localDeals, verbose, showFailed)
if err != nil { if err != nil {
return err return err
} }
@ -1874,7 +1875,7 @@ var clientListDeals = &cli.Command{
} }
} }
return outputStorageDeals(ctx, cctx.App.Writer, api, localDeals, verbose, color, showFailed) return outputStorageDeals(ctx, cctx.App.Writer, api, localDeals, verbose, showFailed)
}, },
} }
@ -1897,7 +1898,7 @@ func dealFromDealInfo(ctx context.Context, full v0api.FullNode, head *types.TipS
} }
} }
func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode, localDeals []lapi.DealInfo, verbose bool, color bool, showFailed bool) error { func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode, localDeals []lapi.DealInfo, verbose bool, showFailed bool) error {
sort.Slice(localDeals, func(i, j int) bool { sort.Slice(localDeals, func(i, j int) bool {
return localDeals[i].CreationTime.Before(localDeals[j].CreationTime) return localDeals[i].CreationTime.Before(localDeals[j].CreationTime)
}) })
@ -1949,7 +1950,7 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode,
d.LocalDeal.ProposalCid, d.LocalDeal.ProposalCid,
d.LocalDeal.DealID, d.LocalDeal.DealID,
d.LocalDeal.Provider, d.LocalDeal.Provider,
dealStateString(color, d.LocalDeal.State), dealStateString(d.LocalDeal.State),
onChain, onChain,
slashed, slashed,
d.LocalDeal.PieceCID, d.LocalDeal.PieceCID,
@ -1998,7 +1999,7 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode,
"DealCid": propcid, "DealCid": propcid,
"DealId": d.LocalDeal.DealID, "DealId": d.LocalDeal.DealID,
"Provider": d.LocalDeal.Provider, "Provider": d.LocalDeal.Provider,
"State": dealStateString(color, d.LocalDeal.State), "State": dealStateString(d.LocalDeal.State),
"On Chain?": onChain, "On Chain?": onChain,
"Slashed?": slashed, "Slashed?": slashed,
"PieceCID": piece, "PieceCID": piece,
@ -2013,12 +2014,8 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode,
return w.Flush(out) return w.Flush(out)
} }
func dealStateString(c bool, state storagemarket.StorageDealStatus) string { func dealStateString(state storagemarket.StorageDealStatus) string {
s := storagemarket.DealStates[state] s := storagemarket.DealStates[state]
if !c {
return s
}
switch state { switch state {
case storagemarket.StorageDealError, storagemarket.StorageDealExpired: case storagemarket.StorageDealError, storagemarket.StorageDealExpired:
return color.RedString(s) return color.RedString(s)
@ -2339,7 +2336,6 @@ var clientListTransfers = &cli.Command{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Usage: "use color in display output", Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
@ -2356,6 +2352,10 @@ var clientListTransfers = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
@ -2370,7 +2370,6 @@ var clientListTransfers = &cli.Command{
verbose := cctx.Bool("verbose") verbose := cctx.Bool("verbose")
completed := cctx.Bool("completed") completed := cctx.Bool("completed")
color := cctx.Bool("color")
watch := cctx.Bool("watch") watch := cctx.Bool("watch")
showFailed := cctx.Bool("show-failed") showFailed := cctx.Bool("show-failed")
if watch { if watch {
@ -2384,7 +2383,7 @@ var clientListTransfers = &cli.Command{
tm.MoveCursor(1, 1) tm.MoveCursor(1, 1)
OutputDataTransferChannels(tm.Screen, channels, verbose, completed, color, showFailed) OutputDataTransferChannels(tm.Screen, channels, verbose, completed, showFailed)
tm.Flush() tm.Flush()
@ -2409,13 +2408,13 @@ var clientListTransfers = &cli.Command{
} }
} }
} }
OutputDataTransferChannels(os.Stdout, channels, verbose, completed, color, showFailed) OutputDataTransferChannels(os.Stdout, channels, verbose, completed, showFailed)
return nil return nil
}, },
} }
// OutputDataTransferChannels generates table output for a list of channels // OutputDataTransferChannels generates table output for a list of channels
func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChannel, verbose, completed, color, showFailed bool) { func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChannel, verbose, completed, showFailed bool) {
sort.Slice(channels, func(i, j int) bool { sort.Slice(channels, func(i, j int) bool {
return channels[i].TransferID < channels[j].TransferID return channels[i].TransferID < channels[j].TransferID
}) })
@ -2445,7 +2444,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann
tablewriter.Col("Voucher"), tablewriter.Col("Voucher"),
tablewriter.NewLineCol("Message")) tablewriter.NewLineCol("Message"))
for _, channel := range sendingChannels { for _, channel := range sendingChannels {
w.Write(toChannelOutput(color, "Sending To", channel, verbose)) w.Write(toChannelOutput("Sending To", channel, verbose))
} }
w.Flush(out) //nolint:errcheck w.Flush(out) //nolint:errcheck
@ -2459,17 +2458,13 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann
tablewriter.Col("Voucher"), tablewriter.Col("Voucher"),
tablewriter.NewLineCol("Message")) tablewriter.NewLineCol("Message"))
for _, channel := range receivingChannels { for _, channel := range receivingChannels {
w.Write(toChannelOutput(color, "Receiving From", channel, verbose)) w.Write(toChannelOutput("Receiving From", channel, verbose))
} }
w.Flush(out) //nolint:errcheck w.Flush(out) //nolint:errcheck
} }
func channelStatusString(useColor bool, status datatransfer.Status) string { func channelStatusString(status datatransfer.Status) string {
s := datatransfer.Statuses[status] s := datatransfer.Statuses[status]
if !useColor {
return s
}
switch status { switch status {
case datatransfer.Failed, datatransfer.Cancelled: case datatransfer.Failed, datatransfer.Cancelled:
return color.RedString(s) return color.RedString(s)
@ -2480,7 +2475,7 @@ func channelStatusString(useColor bool, status datatransfer.Status) string {
} }
} }
func toChannelOutput(useColor bool, otherPartyColumn string, channel lapi.DataTransferChannel, verbose bool) map[string]interface{} { func toChannelOutput(otherPartyColumn string, channel lapi.DataTransferChannel, verbose bool) map[string]interface{} {
rootCid := channel.BaseCID.String() rootCid := channel.BaseCID.String()
otherParty := channel.OtherPeer.String() otherParty := channel.OtherPeer.String()
if !verbose { if !verbose {
@ -2500,7 +2495,7 @@ func toChannelOutput(useColor bool, otherPartyColumn string, channel lapi.DataTr
return map[string]interface{}{ return map[string]interface{}{
"ID": channel.TransferID, "ID": channel.TransferID,
"Status": channelStatusString(useColor, channel.Status), "Status": channelStatusString(channel.Status),
otherPartyColumn: otherParty, otherPartyColumn: otherParty,
"Root Cid": rootCid, "Root Cid": rootCid,
"Initiated?": initiated, "Initiated?": initiated,

View File

@ -3,10 +3,13 @@ package cli
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"time" "time"
"github.com/fatih/color"
"github.com/hako/durafmt" "github.com/hako/durafmt"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/mattn/go-isatty"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
@ -15,6 +18,13 @@ import (
"github.com/filecoin-project/lotus/chain/types" "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) { func parseTipSet(ctx context.Context, api v0api.FullNode, vals []string) (*types.TipSet, error) {
var headers []*types.BlockHeader var headers []*types.BlockHeader
for _, c := range vals { for _, c := range vals {

View File

@ -1,14 +0,0 @@
package cliutil
import (
"os"
"github.com/mattn/go-isatty"
)
// DefaultColorUse is the globally referenced variable for all Lotus CLI tools
// It sets to `true` if STDOUT is a TTY or if the variable GOLOG_LOG_FMT is set
// to color (as recognizd by github.com/ipfs/go-log/v2)
var DefaultColorUse = os.Getenv("GOLOG_LOG_FMT") == "color" ||
isatty.IsTerminal(os.Stdout.Fd()) ||
isatty.IsCygwinTerminal(os.Stdout.Fd())

View File

@ -20,7 +20,6 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/tablewriter" "github.com/filecoin-project/lotus/lib/tablewriter"
) )
@ -267,12 +266,14 @@ var actorControlList = &cli.Command{
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
var maddr address.Address var maddr address.Address
if act := cctx.String("actor"); act != "" { if act := cctx.String("actor"); act != "" {

View File

@ -26,7 +26,6 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/tablewriter" "github.com/filecoin-project/lotus/lib/tablewriter"
) )
@ -390,12 +389,14 @@ var actorControlList = &cli.Command{
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {

View File

@ -49,8 +49,6 @@ var infoCmd = &cli.Command{
} }
func infoCmdAct(cctx *cli.Context) error { func infoCmdAct(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {
return err return err

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/fatih/color"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"go.opencensus.io/trace" "go.opencensus.io/trace"
@ -13,7 +14,6 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/lotuslog" "github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/lib/tracing" "github.com/filecoin-project/lotus/lib/tracing"
"github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/node/repo"
@ -62,9 +62,14 @@ func main() {
trace.UnregisterExporter(jaeger) trace.UnregisterExporter(jaeger)
jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name) jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name)
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
if originBefore != nil { if originBefore != nil {
return originBefore(cctx) return originBefore(cctx)
} }
return nil return nil
} }
} }
@ -82,8 +87,9 @@ func main() {
Aliases: []string{"a"}, Aliases: []string{"a"},
}, },
&cli.BoolFlag{ &cli.BoolFlag{
// examined in the Before above
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
&cli.StringFlag{ &cli.StringFlag{

View File

@ -15,6 +15,7 @@ import (
tm "github.com/buger/goterm" tm "github.com/buger/goterm"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/fatih/color"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-cidutil/cidenc" "github.com/ipfs/go-cidutil/cidenc"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
@ -30,7 +31,6 @@ import (
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
) )
var CidBaseFlag = cli.StringFlag{ var CidBaseFlag = cli.StringFlag{
@ -755,7 +755,6 @@ var transfersListCmd = &cli.Command{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Usage: "use color in display output", Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
@ -772,6 +771,10 @@ var transfersListCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {
return err return err
@ -786,7 +789,6 @@ var transfersListCmd = &cli.Command{
verbose := cctx.Bool("verbose") verbose := cctx.Bool("verbose")
completed := cctx.Bool("completed") completed := cctx.Bool("completed")
color := cctx.Bool("color")
watch := cctx.Bool("watch") watch := cctx.Bool("watch")
showFailed := cctx.Bool("show-failed") showFailed := cctx.Bool("show-failed")
if watch { if watch {
@ -800,7 +802,7 @@ var transfersListCmd = &cli.Command{
tm.MoveCursor(1, 1) tm.MoveCursor(1, 1)
lcli.OutputDataTransferChannels(tm.Screen, channels, verbose, completed, color, showFailed) lcli.OutputDataTransferChannels(tm.Screen, channels, verbose, completed, showFailed)
tm.Flush() tm.Flush()
@ -825,7 +827,7 @@ var transfersListCmd = &cli.Command{
} }
} }
} }
lcli.OutputDataTransferChannels(os.Stdout, channels, verbose, completed, color, showFailed) lcli.OutputDataTransferChannels(os.Stdout, channels, verbose, completed, showFailed)
return nil return nil
}, },
} }

View File

@ -36,8 +36,6 @@ var provingFaultsCmd = &cli.Command{
Name: "faults", Name: "faults",
Usage: "View the currently known proving faulty sectors information", Usage: "View the currently known proving faulty sectors information",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
api, acloser, err := lcli.GetFullNodeAPI(cctx) api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
@ -90,8 +88,6 @@ var provingInfoCmd = &cli.Command{
Name: "info", Name: "info",
Usage: "View current state information", Usage: "View current state information",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
api, acloser, err := lcli.GetFullNodeAPI(cctx) api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
@ -197,8 +193,6 @@ var provingDeadlinesCmd = &cli.Command{
Name: "deadlines", Name: "deadlines",
Usage: "View the current proving period deadlines information", Usage: "View the current proving period deadlines information",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
api, acloser, err := lcli.GetFullNodeAPI(cctx) api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err

View File

@ -19,7 +19,6 @@ import (
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
) )
var sealingCmd = &cli.Command{ var sealingCmd = &cli.Command{
@ -39,12 +38,14 @@ var sealingWorkersCmd = &cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {
@ -134,7 +135,7 @@ var sealingJobsCmd = &cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
@ -143,7 +144,9 @@ var sealingJobsCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {

View File

@ -26,7 +26,6 @@ import (
"github.com/filecoin-project/lotus/lib/tablewriter" "github.com/filecoin-project/lotus/lib/tablewriter"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing" sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
) )
@ -163,9 +162,9 @@ var sectorsListCmd = &cli.Command{
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Aliases: []string{"c"}, Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
Aliases: []string{"c"},
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "fast", Name: "fast",
@ -185,7 +184,9 @@ var sectorsListCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {

View File

@ -27,7 +27,6 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli" lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
"github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/stores"
"github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/extern/sector-storage/storiface"
@ -169,7 +168,7 @@ var storageListCmd = &cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
}, },
@ -177,7 +176,9 @@ var storageListCmd = &cli.Command{
storageListSectorsCmd, storageListSectorsCmd,
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {
@ -484,12 +485,14 @@ var storageListSectorsCmd = &cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "color", Name: "color",
Value: cliutil.DefaultColorUse, Usage: "use color in display output",
DefaultText: "depends on output being a TTY", DefaultText: "depends on output being a TTY",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color") if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil { if err != nil {

View File

@ -41,7 +41,7 @@ COMMANDS:
GLOBAL OPTIONS: GLOBAL OPTIONS:
--actor value, -a value specify other actor to check state for (read only) --actor value, -a value specify other actor to check state for (read only)
--color (default: depends on output being a TTY) --color use color in display output (default: depends on output being a TTY)
--miner-repo value, --storagerepo value Specify miner repo path. flag(storagerepo) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON (default: "~/.lotusminer") [$LOTUS_MINER_PATH, $LOTUS_STORAGE_PATH] --miner-repo value, --storagerepo value Specify miner repo path. flag(storagerepo) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON (default: "~/.lotusminer") [$LOTUS_MINER_PATH, $LOTUS_STORAGE_PATH]
--help, -h show help (default: false) --help, -h show help (default: false)
--version, -v print the version (default: false) --version, -v print the version (default: false)
@ -314,7 +314,7 @@ USAGE:
OPTIONS: OPTIONS:
--verbose (default: false) --verbose (default: false)
--color (default: depends on output being a TTY) --color use color in display output (default: depends on output being a TTY)
--help, -h show help (default: false) --help, -h show help (default: false)
``` ```
@ -1363,7 +1363,7 @@ USAGE:
OPTIONS: OPTIONS:
--show-removed show removed sectors (default: false) --show-removed show removed sectors (default: false)
--color, -c (default: depends on output being a TTY) --color, -c use color in display output (default: depends on output being a TTY)
--fast don't show on-chain info for better performance (default: false) --fast don't show on-chain info for better performance (default: false)
--events display number of events the sector has received (default: false) --events display number of events the sector has received (default: false)
--seal-time display how long it took for the sector to be sealed (default: false) --seal-time display how long it took for the sector to be sealed (default: false)
@ -1759,7 +1759,7 @@ COMMANDS:
help, h Shows a list of commands or help for one command help, h Shows a list of commands or help for one command
OPTIONS: OPTIONS:
--color (default: depends on output being a TTY) --color use color in display output (default: depends on output being a TTY)
--help, -h show help (default: false) --help, -h show help (default: false)
--version, -v print the version (default: false) --version, -v print the version (default: false)
@ -1774,7 +1774,7 @@ USAGE:
lotus-miner storage list sectors [command options] [arguments...] lotus-miner storage list sectors [command options] [arguments...]
OPTIONS: OPTIONS:
--color (default: depends on output being a TTY) --color use color in display output (default: depends on output being a TTY)
--help, -h show help (default: false) --help, -h show help (default: false)
``` ```
@ -1836,7 +1836,7 @@ USAGE:
lotus-miner sealing jobs [command options] [arguments...] lotus-miner sealing jobs [command options] [arguments...]
OPTIONS: OPTIONS:
--color (default: depends on output being a TTY) --color use color in display output (default: depends on output being a TTY)
--show-ret-done show returned but not consumed calls (default: false) --show-ret-done show returned but not consumed calls (default: false)
--help, -h show help (default: false) --help, -h show help (default: false)
@ -1851,7 +1851,7 @@ USAGE:
lotus-miner sealing workers [command options] [arguments...] lotus-miner sealing workers [command options] [arguments...]
OPTIONS: OPTIONS:
--color (default: depends on output being a TTY) --color use color in display output (default: depends on output being a TTY)
--help, -h show help (default: false) --help, -h show help (default: false)
``` ```