-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.go
82 lines (72 loc) · 1.86 KB
/
run.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
73
74
75
76
77
78
79
80
81
82
package main
import (
"time"
"github.com/alecthomas/kong"
"github.com/wudizhangzhi/HupuApp/gohupu/api"
"github.com/wudizhangzhi/HupuApp/gohupu/api_utils"
"github.com/wudizhangzhi/HupuApp/gohupu/live"
"github.com/wudizhangzhi/HupuApp/gohupu/menu"
"github.com/wudizhangzhi/HupuApp/gohupu/spider"
"github.com/wudizhangzhi/HupuApp/gohupu/view"
)
type LiveCmd struct {
GameType api.GameType `arg:"" name:"gameType" help:"比赛类型(nba/cba)."`
}
// 直播
func (r *LiveCmd) Run() error {
matches, _ := api_utils.GetMatchesFromDate(r.GameType)
if len(matches) == 0 {
matches, _ = api_utils.GetAnyMatches(api.NBA, 10, false)
}
interfaceItems := make([]interface{}, 0)
for _, item := range matches {
interfaceItems = append(interfaceItems, item)
}
m := menu.Menu{
Label: menu.LabelLive,
Items: interfaceItems,
Templates: menu.LiveTemplate,
Size: len(interfaceItems),
}
idx, err := m.Start()
if err != nil {
return err
}
match := matches[idx]
client := live.New(match)
// // 退出过快可能导致print打印不显示
time.Sleep(1 * time.Second)
client.Start()
return nil
}
type NewsCmd struct {
Region spider.Region `arg:"" name:"region" help:"领域(nba/cba/湿乎乎/步行街)."`
}
func (r *NewsCmd) Run() error {
spider.New()
view.NewApp()
bbsView := view.NewBBSView(r.Region)
bbsView.Display()
return nil
}
var cli struct {
Debug bool `help:"Enable debug mode."`
Live LiveCmd `cmd:"" help:"比赛直播."`
News NewsCmd `cmd:"" help:"新闻、帖子."`
}
func main() {
ctx := kong.Parse(&cli,
kong.Name("Hupu"),
kong.Description("A command line tool for Hupu."),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Tree: true,
Compact: true,
Summary: true,
FlagsLast: true,
// NoExpandSubcommands: true,
}))
// TODO 读取配置, 注册signal
err := ctx.Run()
ctx.FatalIfErrorf(err)
}