forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffs_info.go
More file actions
64 lines (53 loc) · 1.62 KB
/
ffs_info.go
File metadata and controls
64 lines (53 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cmd
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/caarlos0/spin"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/textileio/powergate/util"
)
func init() {
ffsInfoCmd.Flags().StringP("token", "t", "", "token of the request")
ffsCmd.AddCommand(ffsInfoCmd)
}
var ffsInfoCmd = &cobra.Command{
Use: "info",
Short: "Get info from ffs instance",
Long: `Get info from ffs instance`,
PreRun: func(cmd *cobra.Command, args []string) {
err := viper.BindPFlags(cmd.Flags())
checkErr(err)
},
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
s := spin.New("%s Retrieving instance info...")
s.Start()
info, err := fcClient.FFS.Info(authCtx(ctx))
checkErr(err)
s.Stop()
Message("FFS instance id: %v", info.ID.String())
data := make([][]string, len(info.Balances))
for i, balance := range info.Balances {
isDefault := ""
if balance.Addr == info.DefaultStorageConfig.Cold.Filecoin.Addr {
isDefault = "yes"
}
data[i] = []string{balance.Name, balance.Addr, balance.Type, fmt.Sprintf("%v", balance.Balance), isDefault}
}
Message("Wallet addresses:")
RenderTable(os.Stdout, []string{"name", "address", "type", "balance", "default"}, data)
bytes, err := json.MarshalIndent(info.DefaultStorageConfig, "", " ")
checkErr(err)
Message("Default storage config:\n%v", string(bytes))
Message("Pinned cids:")
data = make([][]string, len(info.Pins))
for i, cid := range info.Pins {
data[i] = []string{util.CidToString(cid)}
}
RenderTable(os.Stdout, []string{"cid"}, data)
},
}