forked from saniales/golang-crypto-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
72 lines (60 loc) · 2.16 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
69
70
71
72
// Copyright © 2017 Alessandro Sanino <saninoale@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package bot
import (
"fmt"
"os"
"os/signal"
"github.com/spf13/cobra"
)
const (
versionNumber = "0.0.1-pre-alpha"
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "gobot",
Short: fmt.Sprintf("USAGE %s [OPTIONS]", os.Args[0]),
Long: fmt.Sprintf(`USAGE %s [OPTIONS] : see --help for details`, os.Args[0]),
Run: executeRootCommand,
}
var signals chan os.Signal
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func init() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
go func() {
<-signals
signal.Stop(signals)
fmt.Println()
fmt.Println("CTRL-C command received. Exiting...")
os.Exit(0)
}()
RootCmd.Flags().BoolVarP(&rootFlags.Version, "version", "V", false, "show version information.")
RootCmd.PersistentFlags().CountVarP(&GlobalFlags.Verbose, "verbose", "v", "show verbose information when trading : use multiple times to increase verbosity level.")
RootCmd.PersistentFlags().StringVar(&GlobalFlags.ConfigFile, "config-file", "./.bot_config.yaml", "Config file path (default : ./.bot_config.yaml)")
}
func executeRootCommand(cmd *cobra.Command, args []string) {
if rootFlags.Version {
fmt.Printf("Golang Crypto Trading Bot v. %s\n", versionNumber)
} else {
cmd.Help()
}
}