-
Notifications
You must be signed in to change notification settings - Fork 20
/
getNodesCommand.go
37 lines (30 loc) · 960 Bytes
/
getNodesCommand.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
package main
import (
"os"
"time"
"github.com/ernoaapa/eliot/cmd"
"github.com/ernoaapa/eliot/pkg/cmd/ui"
"github.com/ernoaapa/eliot/pkg/discovery"
"github.com/ernoaapa/eliot/pkg/printers"
"github.com/urfave/cli"
)
var getNodesCommand = cli.Command{
Name: "nodes",
Aliases: []string{"node", "devices"}, // devices is deprecated command
Usage: "Get Node resources",
UsageText: `eli get nodes [options]
# Get table of known nodes
eli get nodes`,
Action: func(clicontext *cli.Context) error {
uiline := ui.NewLine().Loading("Discover from network automatically...")
nodes, err := discovery.Nodes(5 * time.Second)
if err != nil {
uiline.Fatalf("Failed to auto-discover nodes in network: %s", err)
}
uiline.Donef("Discovered %d nodes from network", len(nodes))
writer := printers.GetNewTabWriter(os.Stdout)
defer writer.Flush()
printer := cmd.GetPrinter(clicontext)
return printer.PrintNodes(nodes, writer)
},
}