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
/
user.go
70 lines (62 loc) · 1.53 KB
/
user.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
package cmd
import (
"github.com/arrow2nd/twnyan/util"
"github.com/gookit/color"
"gopkg.in/abiosoft/ishell.v2"
)
func init() {
showUserTL := func(screenName, counts string) {
err := tweets.LoadUserTL(screenName, counts)
if err != nil {
return
}
tweets.DrawTweets()
tweets.DrawUserInfo(0)
}
userCmd := &ishell.Cmd{
Name: "user",
Aliases: []string{"ur"},
Help: "get a user timeline",
LongHelp: createLongHelp(
"Get a user timeline.\nIf you omit the counts, the default value in the configuration file (25 by default) will be specified.",
"ur",
"user [<username/tweetnumber>] [counts]",
"user github 25\n user 2",
),
Func: func(c *ishell.Context) {
// 引数をパース
user, counts, err := parseTLCmdArgs(c.Args)
if err != nil {
showWrongMsg(c.Cmd.Name)
return
}
// スクリーンネームを取得
if util.IsNumber(user) {
user, err = tweets.GetDataFromTweetNum(user, "ScreenName")
if err != nil {
color.Error.Prompt(err.Error())
return
}
}
// 表示
showUserTL(user, counts)
},
}
userCmd.AddCmd(&ishell.Cmd{
Name: "myuser",
Help: "get your own timeline",
LongHelp: createLongHelp(
"Get your own timeline.\nIf you omit the counts, the default value in the configuration file (25 by default) will be specified.",
"",
"user myuser [counts]",
"user myuser 25",
),
Func: func(c *ishell.Context) {
// 取得件数
counts := getCountsFromCmdArg(c.Args)
// 表示
showUserTL("", counts)
},
})
shell.AddCmd(userCmd)
}