forked from ava-labs/coreth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
45 lines (34 loc) · 822 Bytes
/
params.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package main
import (
"flag"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
func corethFlagSet() *flag.FlagSet {
fs := flag.NewFlagSet("coreth", flag.ContinueOnError)
fs.Bool(versionKey, false, "If true, print version and quit")
return fs
}
// getViper returns the viper environment for the plugin binary
func getViper() (*viper.Viper, error) {
v := viper.New()
fs := corethFlagSet()
pflag.CommandLine.AddGoFlagSet(fs)
pflag.Parse()
if err := v.BindPFlags(pflag.CommandLine); err != nil {
return nil, err
}
return v, nil
}
func PrintVersion() (bool, error) {
v, err := getViper()
if err != nil {
return false, err
}
if v.GetBool(versionKey) {
return true, nil
}
return false, nil
}