-
Notifications
You must be signed in to change notification settings - Fork 496
/
root.go
68 lines (58 loc) · 1.42 KB
/
root.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
package cmd
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
horizonclient "github.com/stellar/go/clients/horizonclient"
hlog "github.com/stellar/go/support/log"
)
var DatabaseURL string
var Client *horizonclient.Client
var UseTestNet bool
var Logger = hlog.New()
var defaultDatabaseURL = getEnv("DB_URL", "postgres://localhost:5432/stellarticker01?sslmode=disable")
var rootCmd = &cobra.Command{
Use: "ticker",
Short: "Stellar Development Foundation Ticker.",
Long: `A tool to provide Stellar Asset and Market data.`,
}
func getEnv(key, fallback string) string {
value, exists := os.LookupEnv(key)
if !exists {
value = fallback
}
return value
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVarP(
&DatabaseURL,
"db-url",
"d",
defaultDatabaseURL,
"database URL, such as: postgres://user:pass@localhost:5432/ticker",
)
rootCmd.PersistentFlags().BoolVar(
&UseTestNet,
"testnet",
false,
"use the Stellar Test Network, instead of the Stellar Public Network",
)
Logger.SetLevel(logrus.DebugLevel)
}
func initConfig() {
if UseTestNet {
Logger.Debug("Using Stellar Default Test Network")
Client = horizonclient.DefaultTestNetClient
} else {
Logger.Debug("Using Stellar Default Public Network")
Client = horizonclient.DefaultPublicNetClient
}
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}