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
66 lines (61 loc) · 1.58 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
package cmd
import (
"fmt"
"github.com/arrow2nd/ishell"
"github.com/arrow2nd/twnyan/util"
)
func (cmd *Cmd) newListCmd() {
cmd.shell.AddCmd(&ishell.Cmd{
Name: "list",
Aliases: []string{"ls"},
Func: cmd.listCmd,
Help: "get the list timeline",
LongHelp: createLongHelp(
"Get the list timeline.\nYou can use the tab key to complete the list name.\nIf you omit the counts, the default value in the configuration file (25 by default) will be specified.",
"ls",
"list [<listname>] [counts]",
"list cats 50",
),
Completer: cmd.listCmdCompleter,
})
}
func (cmd *Cmd) listCmd(c *ishell.Context) {
// 引数をパース
name, counts, err := cmd.parseTLCmdArgs(c.Args)
if err != nil {
cmd.drawWrongArgMessage(c.Cmd.Name)
return
}
// リスト名がリスト内にあるかチェック
i := util.IndexOf(cmd.api.ListNames, name)
if i == -1 {
cmd.drawErrorMessage("No list exists!")
return
}
// リストタイムラインを取得
t, err := cmd.api.GetListTimeline(cmd.api.ListIDs[i], counts)
if err != nil {
cmd.drawErrorMessage(err.Error())
return
}
// 描画
cmd.view.RegisterTweets(t)
cmd.view.DrawTweets()
}
func (cmd *Cmd) listCmdCompleter([]string) []string {
// リストの存在チェック
if cmd.api.ListNames == nil {
return nil
}
// 補完用スライス作成
cmp := make([]string, len(cmd.api.ListNames))
for i, v := range cmd.api.ListNames {
if util.ContainsStr("\\s", v) {
// リスト名に空白があればダブルクオートで囲む
cmp[i] = fmt.Sprintf("\"%s\"", v)
} else {
cmp[i] = v
}
}
return cmp
}