-
Notifications
You must be signed in to change notification settings - Fork 88
/
utils.go
46 lines (40 loc) · 986 Bytes
/
utils.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
package cmd
import (
"os"
"strings"
"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/multiformats/go-multiaddr"
"github.com/spf13/cobra"
)
func getCommandLineExecutable() string {
return os.Args[0]
}
func FatalErrorHandler(cmd *cobra.Command, msg string, code int) {
if len(msg) > 0 {
// add newline if needed
if !strings.HasSuffix(msg, "\n") {
msg += "\n"
}
cmd.Print(msg)
}
os.Exit(code)
}
func getPeers(peerConnect string) ([]multiaddr.Multiaddr, error) {
var peersStrings []string
if peerConnect == "none" {
peersStrings = []string{}
} else if peerConnect == "" {
peersStrings = system.Envs[system.EnvironmentProd].BootstrapAddresses
} else {
peersStrings = strings.Split(peerConnect, ",")
}
peers := make([]multiaddr.Multiaddr, 0, len(peersStrings))
for _, peer := range peersStrings {
parsed, err := multiaddr.NewMultiaddr(peer)
if err != nil {
return nil, err
}
peers = append(peers, parsed)
}
return peers, nil
}