-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
104 lines (85 loc) · 2.02 KB
/
list.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package cmd
import (
"github.com/urfave/cli"
"github.com/AkihikoITOH/lesen/model/feedly"
"github.com/AkihikoITOH/lesen/query"
"github.com/AkihikoITOH/lesen/ui"
)
var listCommand = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List the feeds.",
Subcommands: []cli.Command{
listDirectoriesCommand,
listSourcesCommand,
listArticlesCommand,
},
}
var listDirectoriesCommand = cli.Command{
Name: "directories",
Aliases: []string{"d"},
Usage: "List the directories.",
Action: listDirectoriesAction,
Flags: []cli.Flag{
inputFileLocationFlag,
feedModeFlag,
},
}
var listSourcesCommand = cli.Command{
Name: "sources",
Aliases: []string{"s"},
Usage: "List the feed sources.",
Action: listSourcesAction,
Flags: []cli.Flag{
inputFileLocationFlag,
directoryTitlesFlag,
feedModeFlag,
},
}
var listArticlesCommand = cli.Command{
Name: "articles",
Aliases: []string{"a"},
Usage: "List the articles.",
Action: listArticlesAction,
Flags: []cli.Flag{
inputFileLocationFlag,
directoryTitlesFlag,
feedModeFlag,
},
}
func listDirectoriesAction(c *cli.Context) error {
root, err := feedly.NewFeedsFromOPML(c.String("input"))
if err != nil {
return err
}
cui := ui.NewCUI(root, ui.DirectoryLevel)
cui.Draw()
return nil
}
func listSourcesAction(c *cli.Context) error {
root, err := feedly.NewFeedsFromOPML(c.String("input"))
if err != nil {
return err
}
q := &query.Query{Root: root}
opts := query.CollectDirectoriesOpts{Titles: c.StringSlice("directories")}
q = q.CollectDirectories(opts)
filtered := q.Root
cui := ui.NewCUI(filtered, ui.SourceLevel)
cui.Draw()
return nil
}
func listArticlesAction(c *cli.Context) error {
root, err := feedly.NewFeedsFromOPML(c.String("input"))
if err != nil {
return err
}
q := &query.Query{Root: root}
opts := query.CollectDirectoriesOpts{Titles: c.StringSlice("directories")}
q = q.CollectDirectories(opts)
filtered := q.Root
filtered.FetchSources()
cui := ui.NewCUI(filtered, ui.ArticleLevel)
cui.Draw()
return nil
}