forked from aergoio/aergo
/
nodestate.go
52 lines (42 loc) · 984 Bytes
/
nodestate.go
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
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package cmd
import (
"context"
"encoding/binary"
"github.com/aergoio/aergo/types"
"github.com/spf13/cobra"
)
var (
nodeCmd = &cobra.Command{
Use: "node",
Short: "Show internal metric",
Args: cobra.MinimumNArgs(0),
Run: execNodeState,
}
component string
)
func init() {
rootCmd.AddCommand(nodeCmd)
nodeCmd.Flags().Uint64VarP(&timeout, "timeout", "t", 3, "Per module time out")
nodeCmd.Flags().StringVarP(&component, "component", "c", "", "component name")
}
func execNodeState(cmd *cobra.Command, args []string) {
var b []byte
var nodeReq types.NodeReq
if len(component) > 0 {
b = []byte(component)
nodeReq.Component = b
}
b = make([]byte, 8)
binary.LittleEndian.PutUint64(b, timeout)
nodeReq.Timeout = b
msg, err := client.NodeState(context.Background(), &nodeReq)
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
return
}
cmd.Printf("%s\n", string(msg.Value))
}