Merge pull request #6696 from filecoin-project/chore/even-less-color-on-cli
Enable color by default only if os.Stdout is a TTY
This commit is contained in:
commit
e258e7c353
@ -45,6 +45,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1233,7 +1234,8 @@ 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: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "show-failed",
|
Name: "show-failed",
|
||||||
@ -1806,7 +1808,8 @@ 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: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "show-failed",
|
Name: "show-failed",
|
||||||
@ -2336,7 +2339,8 @@ 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: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "completed",
|
Name: "completed",
|
||||||
|
14
cli/util/color.go
Normal file
14
cli/util/color.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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())
|
@ -20,6 +20,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -266,7 +267,8 @@ var actorControlList = &cli.Command{
|
|||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "color",
|
Name: "color",
|
||||||
Value: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
|
@ -26,6 +26,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -389,7 +390,8 @@ var actorControlList = &cli.Command{
|
|||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "color",
|
Name: "color",
|
||||||
Value: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
|
@ -13,6 +13,7 @@ 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"
|
||||||
@ -82,6 +83,8 @@ func main() {
|
|||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "color",
|
Name: "color",
|
||||||
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo",
|
Name: "repo",
|
||||||
|
@ -30,6 +30,7 @@ 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{
|
||||||
@ -754,7 +755,8 @@ 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: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "completed",
|
Name: "completed",
|
||||||
|
@ -19,6 +19,7 @@ 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{
|
||||||
@ -36,7 +37,11 @@ var sealingWorkersCmd = &cli.Command{
|
|||||||
Name: "workers",
|
Name: "workers",
|
||||||
Usage: "list workers",
|
Usage: "list workers",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{Name: "color"},
|
&cli.BoolFlag{
|
||||||
|
Name: "color",
|
||||||
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
color.NoColor = !cctx.Bool("color")
|
color.NoColor = !cctx.Bool("color")
|
||||||
@ -127,7 +132,11 @@ var sealingJobsCmd = &cli.Command{
|
|||||||
Name: "jobs",
|
Name: "jobs",
|
||||||
Usage: "list running jobs",
|
Usage: "list running jobs",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{Name: "color"},
|
&cli.BoolFlag{
|
||||||
|
Name: "color",
|
||||||
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "show-ret-done",
|
Name: "show-ret-done",
|
||||||
Usage: "show returned but not consumed calls",
|
Usage: "show returned but not consumed calls",
|
||||||
|
@ -26,6 +26,7 @@ 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,7 +164,8 @@ var sectorsListCmd = &cli.Command{
|
|||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "color",
|
Name: "color",
|
||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
Value: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "fast",
|
Name: "fast",
|
||||||
|
@ -27,6 +27,7 @@ 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"
|
||||||
@ -166,7 +167,11 @@ var storageListCmd = &cli.Command{
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "list local storage paths",
|
Usage: "list local storage paths",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{Name: "color"},
|
&cli.BoolFlag{
|
||||||
|
Name: "color",
|
||||||
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
storageListSectorsCmd,
|
storageListSectorsCmd,
|
||||||
@ -479,7 +484,8 @@ var storageListSectorsCmd = &cli.Command{
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "color",
|
Name: "color",
|
||||||
Value: true,
|
Value: cliutil.DefaultColorUse,
|
||||||
|
DefaultText: "depends on output being a TTY",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
|
@ -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: false)
|
--color (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)
|
||||||
@ -295,7 +295,7 @@ USAGE:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--verbose (default: false)
|
--verbose (default: false)
|
||||||
--color (default: true)
|
--color (default: depends on output being a TTY)
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -888,7 +888,7 @@ USAGE:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--verbose, -v print verbose transfer details (default: false)
|
--verbose, -v print verbose transfer details (default: false)
|
||||||
--color use color in display output (default: true)
|
--color use color in display output (default: depends on output being a TTY)
|
||||||
--completed show completed data transfers (default: false)
|
--completed show completed data transfers (default: false)
|
||||||
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
||||||
--show-failed show failed/cancelled transfers (default: false)
|
--show-failed show failed/cancelled transfers (default: false)
|
||||||
@ -1344,7 +1344,7 @@ USAGE:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--show-removed show removed sectors (default: false)
|
--show-removed show removed sectors (default: false)
|
||||||
--color, -c (default: true)
|
--color, -c (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)
|
||||||
@ -1739,7 +1739,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: false)
|
--color (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)
|
||||||
|
|
||||||
@ -1754,7 +1754,7 @@ USAGE:
|
|||||||
lotus-miner storage list sectors [command options] [arguments...]
|
lotus-miner storage list sectors [command options] [arguments...]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--color (default: true)
|
--color (default: depends on output being a TTY)
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -1816,7 +1816,7 @@ USAGE:
|
|||||||
lotus-miner sealing jobs [command options] [arguments...]
|
lotus-miner sealing jobs [command options] [arguments...]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--color (default: false)
|
--color (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)
|
||||||
|
|
||||||
@ -1831,7 +1831,7 @@ USAGE:
|
|||||||
lotus-miner sealing workers [command options] [arguments...]
|
lotus-miner sealing workers [command options] [arguments...]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--color (default: false)
|
--color (default: depends on output being a TTY)
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -535,7 +535,7 @@ CATEGORY:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--verbose, -v print verbose deal details (default: false)
|
--verbose, -v print verbose deal details (default: false)
|
||||||
--color use color in display output (default: true)
|
--color use color in display output (default: depends on output being a TTY)
|
||||||
--show-failed show failed/failing deals (default: true)
|
--show-failed show failed/failing deals (default: true)
|
||||||
--completed show completed retrievals (default: false)
|
--completed show completed retrievals (default: false)
|
||||||
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
||||||
@ -609,7 +609,7 @@ CATEGORY:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--verbose, -v print verbose deal details (default: false)
|
--verbose, -v print verbose deal details (default: false)
|
||||||
--color use color in display output (default: true)
|
--color use color in display output (default: depends on output being a TTY)
|
||||||
--show-failed show failed/failing deals (default: false)
|
--show-failed show failed/failing deals (default: false)
|
||||||
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
||||||
--help, -h show help (default: false)
|
--help, -h show help (default: false)
|
||||||
@ -747,7 +747,7 @@ CATEGORY:
|
|||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--verbose, -v print verbose transfer details (default: false)
|
--verbose, -v print verbose transfer details (default: false)
|
||||||
--color use color in display output (default: true)
|
--color use color in display output (default: depends on output being a TTY)
|
||||||
--completed show completed data transfers (default: false)
|
--completed show completed data transfers (default: false)
|
||||||
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
--watch watch deal updates in real-time, rather than a one time list (default: false)
|
||||||
--show-failed show failed/cancelled transfers (default: false)
|
--show-failed show failed/cancelled transfers (default: false)
|
||||||
|
Loading…
Reference in New Issue
Block a user