/
sina_cmd.go
61 lines (48 loc) · 1.44 KB
/
sina_cmd.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
package main
import (
"fmt"
//"github.com/saycv/tsgo"
//"github.com/saycv/tsgo/pkg/configuration"
logsupport "github.com/saycv/tsgo/pkg/log"
TerminalStocks "github.com/saycv/tsgo/pkg/terminalstocks"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// NewSinaAPICmd returns the root command
func NewSinaAPICmd() *cobra.Command {
var logLevel string
rootCmd := &cobra.Command{
Use: "sina",
Short: `Fetch finance from Sina API`,
Args: cobra.ArbitraryArgs,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
lvl, err := log.ParseLevel(logLevel)
if err != nil {
fmt.Fprintf(cmd.OutOrStderr(), "unable to parse log level '%v'", logLevel)
return err
}
logsupport.Setup()
log.SetLevel(lvl)
log.SetOutput(cmd.OutOrStdout())
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
//if len(args) <= 1 {
// return helpCommand.RunE(cmd, args)
//}
//attrs := parseAttributes(attributes)
//for _, sourcePath := range args {
//}
screen := TerminalStocks.NewScreen(TerminalStocks.API_VENDOR_SINA)
defer screen.Close()
profile := TerminalStocks.NewProfile(TerminalStocks.API_VENDOR_SINA)
mainLoop(screen, profile)
return nil
},
}
rootCmd.SilenceUsage = true
flags := rootCmd.Flags()
flags.StringVarP(&logLevel, "log", "l", "debug", "log level to set [debug|info|warning|error|fatal|panic]")
// rootCmd.MarkFlagRequired("logLevel")
return rootCmd
}