-
Notifications
You must be signed in to change notification settings - Fork 672
/
main.go
72 lines (58 loc) · 1.44 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"github.com/spf13/pflag"
"golang.org/x/term"
"github.com/ava-labs/avalanchego/app"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/version"
)
func main() {
fs := config.BuildFlagSet()
v, err := config.BuildViper(fs, os.Args[1:])
if errors.Is(err, pflag.ErrHelp) {
os.Exit(0)
}
if err != nil {
fmt.Printf("couldn't configure flags: %s\n", err)
os.Exit(1)
}
if v.GetBool(config.VersionJSONKey) && v.GetBool(config.VersionKey) {
fmt.Println("can't print both JSON and human readable versions")
os.Exit(1)
}
if v.GetBool(config.VersionJSONKey) {
versions := version.GetVersions()
jsonBytes, err := json.MarshalIndent(versions, "", " ")
if err != nil {
fmt.Printf("couldn't marshal versions: %s\n", err)
os.Exit(1)
}
fmt.Println(string(jsonBytes))
os.Exit(0)
}
if v.GetBool(config.VersionKey) {
fmt.Println(version.GetVersions().String())
os.Exit(0)
}
nodeConfig, err := config.GetNodeConfig(v)
if err != nil {
fmt.Printf("couldn't load node config: %s\n", err)
os.Exit(1)
}
if term.IsTerminal(int(os.Stdout.Fd())) {
fmt.Println(app.Header)
}
nodeApp, err := app.New(nodeConfig)
if err != nil {
fmt.Printf("couldn't start node: %s\n", err)
os.Exit(1)
}
exitCode := app.Run(nodeApp)
os.Exit(exitCode)
}