-
Notifications
You must be signed in to change notification settings - Fork 151
/
node_info.go
47 lines (36 loc) · 1.14 KB
/
node_info.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
package toolset
import (
"context"
"fmt"
"os"
flag "github.com/spf13/pflag"
"github.com/iotaledger/hive.go/app/configuration"
"github.com/iotaledger/iota.go/v3/nodeclient"
)
func nodeInfo(args []string) error {
fs := configuration.NewUnsortedFlagSet("", flag.ContinueOnError)
nodeURLFlag := fs.String(FlagToolNodeURL, "http://localhost:14265", "URL of the node (optional)")
outputJSONFlag := fs.Bool(FlagToolOutputJSON, false, FlagToolDescriptionOutputJSON)
fs.Usage = func() {
_, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", ToolNodeInfo)
fs.PrintDefaults()
println(fmt.Sprintf("\nexample: %s --%s %s",
ToolNodeInfo,
FlagToolNodeURL,
"http://192.168.1.221:14265",
))
}
if err := parseFlagSet(fs, args); err != nil {
return err
}
client := nodeclient.New(*nodeURLFlag)
info, err := client.Info(context.Background())
if err != nil {
return err
}
if *outputJSONFlag {
return printJSON(info)
}
fmt.Printf("Name: %s\nVersion: %s\nMilestones: %d / %d\nIsHealthy: %s\n", info.Name, info.Version, info.Status.LatestMilestone.Index, info.Status.ConfirmedMilestone.Index, yesOrNo(info.Status.IsHealthy))
return nil
}