-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_setaddr.go
48 lines (36 loc) · 999 Bytes
/
node_setaddr.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
package main
import (
"fmt"
"os"
"github.com/cipherboy/devbao/pkg/bao"
"github.com/urfave/cli/v2"
)
func BuildNodeSetAddressCommand() *cli.Command {
c := &cli.Command{
Name: "set-address",
Aliases: []string{"s-a"},
ArgsUsage: "<name> <token>",
Usage: "save connection address for future use",
Action: RunNodeSetAddressCommand,
}
return c
}
func RunNodeSetAddressCommand(cCtx *cli.Context) error {
if !cCtx.Args().Present() {
return fmt.Errorf("missing required positional argument:\n\t<name>, the node which has this token\n\t<address>, the address to save")
}
name := cCtx.Args().First()
addr := cCtx.Args().Get(1)
node, err := bao.LoadNode(name)
if err != nil {
return fmt.Errorf("failed to load node: %w", err)
}
validated, err := node.SetAddress(addr)
if err != nil {
return err
}
if !validated {
fmt.Fprintf(os.Stderr, "[warning] instance (%v) was not running; could not validate provided addr\n", name)
}
return node.SaveConfig()
}