This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
72 lines (60 loc) · 1.57 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
package cmd
import (
"fmt"
"github.com/arrow2nd/ishell/v2"
"github.com/arrow2nd/twnyan/util"
)
func (cmd *Cmd) newListCmd() *ishell.Cmd {
return &ishell.Cmd{
Name: "list",
Aliases: []string{"ls"},
Completer: cmd.listCmdCompleter,
Func: cmd.execListCmd,
Help: "displays the list timeline",
LongHelp: createLongHelp(
`Displays the list timeline.
You can use the tab key to complete the list name.
If number of acquisitions is omitted, the default value in the configuration file is specified.`,
"ls",
"list <listname> [number]",
"list cats 50",
),
}
}
func (cmd *Cmd) execListCmd(c *ishell.Context) {
name, counts, err := cmd.parseTimelineCmdArgs(c.Args)
if err != nil {
cmd.showWrongArgMessage(c.Cmd.Name)
return
}
// リスト名からリストIDを取得
listId, ok := cmd.twitter.List[name]
if !ok {
cmd.showErrorMessage("Not found in list")
return
}
// リストのツイートを取得
tweets, err := cmd.twitter.FetchListTweets(listId, counts)
if err != nil {
cmd.showErrorMessage(err.Error())
return
}
cmd.twitter.RegisterTweets(tweets)
cmd.showTweets()
}
func (cmd *Cmd) listCmdCompleter([]string) []string {
// リストが無いなら処理しない
if len(cmd.twitter.List) == 0 {
return nil
}
// 入力補完用のスライスを作成
items := []string{}
for name := range cmd.twitter.List {
// リスト名が空白を含んでいるならダブルクオートで囲む
if util.MatchesRegexp("\\s", name) {
name = fmt.Sprintf("\"%s\"", name)
}
items = append(items, name)
}
return items
}