-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_timeline.go
76 lines (63 loc) 路 1.49 KB
/
cmd_timeline.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
package app
import (
"fmt"
"github.com/arrow2nd/nekomata/cli"
"github.com/spf13/pflag"
)
func (a *App) newTimelineCmd() *cli.Command {
timelineCmd := &cli.Command{
Name: "timeline",
Short: "Add timeline page",
Hidden: global.isCLI,
}
timelineCmd.AddCommand(a.newTimelineSubCmds()...)
return timelineCmd
}
func (a *App) newTimelineSubCmds() []*cli.Command {
action := func(t timelineKind, c *cli.Command, f *pflag.FlagSet) error {
page, err := newTimelinePage(t)
if err != nil {
return err
}
openBackground, _ := f.GetBool("background")
if err := a.view.AddPage(page, !openBackground); err != nil {
return err
}
go func() {
if err := page.Load(); err != nil {
label := fmt.Sprintf("load (%s)", t)
global.SetErrorStatus(label, err.Error())
}
}()
return nil
}
home := &cli.Command{
Name: "home",
Short: "Add home timeline page",
SetFlag: setOpenBackgroundFlag,
Run: func(c *cli.Command, f *pflag.FlagSet) error {
return action(homeTimeline, c, f)
},
}
global := &cli.Command{
Name: "global",
Short: "Add global timeline page",
SetFlag: setOpenBackgroundFlag,
Run: func(c *cli.Command, f *pflag.FlagSet) error {
return action(globalTimeline, c, f)
},
}
local := &cli.Command{
Name: "local",
Short: "Add local timeline page",
SetFlag: setOpenBackgroundFlag,
Run: func(c *cli.Command, f *pflag.FlagSet) error {
return action(localTimeline, c, f)
},
}
return []*cli.Command{
home,
global,
local,
}
}