From 7583c4399ad2933a5e61b5354faa56b7da8a940e Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 28 Dec 2020 16:36:19 +0800 Subject: [PATCH] add verbose for list transfers --- cli/client.go | 28 +++++++++++++++++++--------- cmd/lotus-storage-miner/market.go | 10 ++++++++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cli/client.go b/cli/client.go index 129ede94b74..7a6831fe5f9 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1943,6 +1943,11 @@ var clientListTransfers = &cli.Command{ Name: "list-transfers", Usage: "List ongoing data transfers for deals", Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "print verbose transfer details", + }, &cli.BoolFlag{ Name: "color", Usage: "use color in display output", @@ -1974,6 +1979,7 @@ var clientListTransfers = &cli.Command{ return err } + verbose := cctx.Bool("verbose") completed := cctx.Bool("completed") color := cctx.Bool("color") watch := cctx.Bool("watch") @@ -1989,7 +1995,7 @@ var clientListTransfers = &cli.Command{ tm.MoveCursor(1, 1) - OutputDataTransferChannels(tm.Screen, channels, completed, color, showFailed) + OutputDataTransferChannels(tm.Screen, channels, verbose, completed, color, showFailed) tm.Flush() @@ -2014,13 +2020,13 @@ var clientListTransfers = &cli.Command{ } } } - OutputDataTransferChannels(os.Stdout, channels, completed, color, showFailed) + OutputDataTransferChannels(os.Stdout, channels, verbose, completed, color, showFailed) return nil }, } // OutputDataTransferChannels generates table output for a list of channels -func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChannel, completed bool, color bool, showFailed bool) { +func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChannel, verbose, completed, color, showFailed bool) { sort.Slice(channels, func(i, j int) bool { return channels[i].TransferID < channels[j].TransferID }) @@ -2050,7 +2056,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann tablewriter.Col("Voucher"), tablewriter.NewLineCol("Message")) for _, channel := range sendingChannels { - w.Write(toChannelOutput(color, "Sending To", channel)) + w.Write(toChannelOutput(color, "Sending To", channel, verbose)) } w.Flush(out) //nolint:errcheck @@ -2064,7 +2070,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann tablewriter.Col("Voucher"), tablewriter.NewLineCol("Message")) for _, channel := range receivingChannels { - w.Write(toChannelOutput(color, "Receiving From", channel)) + w.Write(toChannelOutput(color, "Receiving From", channel, verbose)) } w.Flush(out) //nolint:errcheck } @@ -2085,9 +2091,13 @@ func channelStatusString(useColor bool, status datatransfer.Status) string { } } -func toChannelOutput(useColor bool, otherPartyColumn string, channel lapi.DataTransferChannel) map[string]interface{} { - rootCid := ellipsis(channel.BaseCID.String(), 8) - otherParty := ellipsis(channel.OtherPeer.String(), 8) +func toChannelOutput(useColor bool, otherPartyColumn string, channel lapi.DataTransferChannel, verbose bool) map[string]interface{} { + rootCid := channel.BaseCID.String() + otherParty := channel.OtherPeer.String() + if !verbose { + rootCid = ellipsis(rootCid, 8) + otherParty = ellipsis(otherParty, 8) + } initiated := "N" if channel.IsInitiator { @@ -2095,7 +2105,7 @@ func toChannelOutput(useColor bool, otherPartyColumn string, channel lapi.DataTr } voucher := channel.Voucher - if len(voucher) > 40 { + if len(voucher) > 40 && !verbose { voucher = ellipsis(voucher, 37) } diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 1e5057f5dd1..51454fd04ed 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -744,6 +744,11 @@ var transfersListCmd = &cli.Command{ Name: "list", Usage: "List ongoing data transfers for this miner", Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "print verbose transfer details", + }, &cli.BoolFlag{ Name: "color", Usage: "use color in display output", @@ -775,6 +780,7 @@ var transfersListCmd = &cli.Command{ return err } + verbose := cctx.Bool("verbose") completed := cctx.Bool("completed") color := cctx.Bool("color") watch := cctx.Bool("watch") @@ -790,7 +796,7 @@ var transfersListCmd = &cli.Command{ tm.MoveCursor(1, 1) - lcli.OutputDataTransferChannels(tm.Screen, channels, completed, color, showFailed) + lcli.OutputDataTransferChannels(tm.Screen, channels, verbose, completed, color, showFailed) tm.Flush() @@ -815,7 +821,7 @@ var transfersListCmd = &cli.Command{ } } } - lcli.OutputDataTransferChannels(os.Stdout, channels, completed, color, showFailed) + lcli.OutputDataTransferChannels(os.Stdout, channels, verbose, completed, color, showFailed) return nil }, }