Skip to content

Commit 25388df

Browse files
committed
fix: .gitignore
1 parent 0076168 commit 25388df

File tree

8 files changed

+403
-0
lines changed

8 files changed

+403
-0
lines changed

cmd/dingtalk/actionCard.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package dingtalk
2+
3+
import (
4+
"github.com/CatchZeng/dingtalk"
5+
"github.com/CatchZeng/gutils/log"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var actionCardCmd = &cobra.Command{
10+
Use: "actionCard",
11+
Short: "send actionCard message with Client robot",
12+
Long: `send actionCard message with Client robot`,
13+
Args: cobra.MinimumNArgs(0),
14+
Run: func(_ *cobra.Command, args []string) {
15+
if !CheckToken() {
16+
log.L(log.Red, "access_token can not be empty")
17+
return
18+
}
19+
20+
if len(actionCardVars.Title) < 1 {
21+
log.L(log.Red, "title can not be empty")
22+
return
23+
}
24+
25+
if len(actionCardVars.Text) < 1 {
26+
log.L(log.Red, "text can not be empty")
27+
return
28+
}
29+
30+
var isOverallJump = false
31+
if len(actionCardVars.SingleTitle) < 1 {
32+
if len(btnTitles) < 1 {
33+
log.L(log.Red, "btns can not be empty when singleTitle is empty")
34+
return
35+
}
36+
} else {
37+
isOverallJump = true
38+
if len(actionCardVars.SingleURL) < 1 {
39+
log.L(log.Red, "singleURL can not be empty")
40+
return
41+
}
42+
}
43+
44+
client := dingtalk.NewClient(rootVars.accessToken, rootVars.secret)
45+
msg := dingtalk.NewActionCardMessage()
46+
if isOverallJump {
47+
msg.SetOverallJump(
48+
actionCardVars.Title,
49+
actionCardVars.Text,
50+
actionCardVars.SingleTitle,
51+
actionCardVars.SingleURL,
52+
actionCardVars.BtnOrientation,
53+
actionCardVars.HideAvatar)
54+
} else {
55+
if len(btnTitles) != len(btnActionURLs) {
56+
log.L(log.Red, "btnTitles & btnActionURLs count must be equal")
57+
return
58+
}
59+
for i := 0; i < len(btnTitles); i++ {
60+
actionCardVars.Btns = append(actionCardVars.Btns, dingtalk.Btn{
61+
Title: btnTitles[i],
62+
ActionURL: btnActionURLs[i],
63+
})
64+
}
65+
msg.SetIndependentJump(
66+
actionCardVars.Title,
67+
actionCardVars.Text,
68+
actionCardVars.Btns,
69+
actionCardVars.BtnOrientation,
70+
actionCardVars.HideAvatar)
71+
}
72+
if _, err := client.Send(msg); err != nil {
73+
log.L(log.Red, err.Error())
74+
}
75+
},
76+
}
77+
78+
var actionCardVars dingtalk.ActionCard
79+
var btnTitles, btnActionURLs []string
80+
81+
func init() {
82+
rootCmd.AddCommand(actionCardCmd)
83+
actionCardCmd.Flags().StringVarP(&actionCardVars.Title, "title", "i", "", "title")
84+
actionCardCmd.Flags().StringVarP(&actionCardVars.Text, "text", "e", "", "text")
85+
actionCardCmd.Flags().StringVarP(&actionCardVars.SingleTitle, "singleTitle", "n", "", "singleTitle")
86+
actionCardCmd.Flags().StringVarP(&actionCardVars.SingleURL, "singleURL", "u", "", "singleURL")
87+
actionCardCmd.Flags().StringSliceVarP(&btnTitles, "btnTitles", "b", []string{}, "btnTitles")
88+
actionCardCmd.Flags().StringSliceVarP(&btnActionURLs, "btnActionURLs", "c", []string{}, "btnActionURLs")
89+
actionCardCmd.Flags().StringVarP(&actionCardVars.BtnOrientation, "btnOrientation", "o", "", "btnOrientation")
90+
actionCardCmd.Flags().StringVarP(&actionCardVars.HideAvatar, "hideAvatar", "d", "", "hideAvatar")
91+
}

cmd/dingtalk/feedCard.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package dingtalk
2+
3+
import (
4+
"github.com/CatchZeng/dingtalk"
5+
"github.com/CatchZeng/gutils/log"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var feedCardCmd = &cobra.Command{
10+
Use: "feedCard",
11+
Short: "send feedCard message with Client robot",
12+
Long: `send feedCard message with Client robot`,
13+
Args: cobra.MinimumNArgs(0),
14+
Run: func(_ *cobra.Command, args []string) {
15+
if !CheckToken() {
16+
log.L(log.Red, "access_token can not be empty")
17+
return
18+
}
19+
20+
if len(feedCardVars.titles) < 1 || len(feedCardVars.picURLs) < 1 || len(feedCardVars.messageURLs) < 1 {
21+
log.L(log.Red, "titles & picURLs & messageURLs can not be empty")
22+
return
23+
}
24+
25+
if len(feedCardVars.titles) == len(feedCardVars.picURLs) && len(feedCardVars.picURLs) == len(feedCardVars.messageURLs) {
26+
client := dingtalk.NewClient(rootVars.accessToken, rootVars.secret)
27+
28+
msg := dingtalk.NewFeedCardMessage()
29+
for i := 0; i < len(feedCardVars.titles); i++ {
30+
msg.AppendLink(feedCardVars.titles[i], feedCardVars.messageURLs[i], feedCardVars.picURLs[i])
31+
}
32+
if _, err := client.Send(msg); err != nil {
33+
log.L(log.Red, err.Error())
34+
}
35+
} else {
36+
log.L(log.Red, "titles & picURLs & messageURLs count must be equal")
37+
return
38+
}
39+
},
40+
}
41+
42+
// FeedCardVars struct
43+
type FeedCardVars struct {
44+
titles []string
45+
picURLs []string
46+
messageURLs []string
47+
}
48+
49+
var feedCardVars FeedCardVars
50+
51+
func init() {
52+
rootCmd.AddCommand(feedCardCmd)
53+
54+
feedCardCmd.Flags().StringSliceVarP(&feedCardVars.titles, "titles", "i", []string{}, "titles")
55+
feedCardCmd.Flags().StringSliceVarP(&feedCardVars.picURLs, "picURLs", "p", []string{}, "picURLs")
56+
feedCardCmd.Flags().StringSliceVarP(&feedCardVars.messageURLs, "messageURLs", "u", []string{}, "messageURLs")
57+
}

cmd/dingtalk/link.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dingtalk
2+
3+
import (
4+
"github.com/CatchZeng/dingtalk"
5+
"github.com/CatchZeng/gutils/log"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var linkCmd = &cobra.Command{
10+
Use: "link",
11+
Short: "send link message with Client robot",
12+
Long: `send link message with Client robot`,
13+
Args: cobra.MinimumNArgs(0),
14+
Run: func(_ *cobra.Command, args []string) {
15+
if !CheckToken() {
16+
log.L(log.Red, "access_token can not be empty")
17+
return
18+
}
19+
20+
if len(linkVars.title) < 1 {
21+
log.L(log.Red, "title can not be empty")
22+
return
23+
}
24+
25+
if len(linkVars.text) < 1 {
26+
log.L(log.Red, "text can not be empty")
27+
return
28+
}
29+
30+
if len(linkVars.messageURL) < 1 {
31+
log.L(log.Red, "messageURL can not be empty")
32+
return
33+
}
34+
35+
client := dingtalk.NewClient(rootVars.accessToken, rootVars.secret)
36+
msg := dingtalk.NewLinkMessage().
37+
SetLink(linkVars.title, linkVars.text, linkVars.picURL, linkVars.messageURL)
38+
if _, err := client.Send(msg); err != nil {
39+
log.L(log.Red, err.Error())
40+
}
41+
},
42+
}
43+
44+
// LinkVars struct
45+
type LinkVars struct {
46+
title string
47+
text string
48+
picURL string
49+
messageURL string
50+
}
51+
52+
var linkVars LinkVars
53+
54+
func init() {
55+
rootCmd.AddCommand(linkCmd)
56+
linkCmd.Flags().StringVarP(&linkVars.title, "title", "i", "", "title")
57+
linkCmd.Flags().StringVarP(&linkVars.text, "text", "e", "", "text")
58+
linkCmd.Flags().StringVarP(&linkVars.picURL, "picURL", "p", "", "picURL")
59+
linkCmd.Flags().StringVarP(&linkVars.messageURL, "messageURL", "u", "", "messageURL")
60+
}

cmd/dingtalk/markdown.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package dingtalk
2+
3+
import (
4+
"github.com/CatchZeng/dingtalk"
5+
"github.com/CatchZeng/gutils/log"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var markdownCmd = &cobra.Command{
10+
Use: "markdown",
11+
Short: "send markdown message with Client robot",
12+
Long: `send markdown message with Client robot`,
13+
Args: cobra.MinimumNArgs(0),
14+
Run: func(_ *cobra.Command, args []string) {
15+
if !CheckToken() {
16+
log.L(log.Red, "access_token can not be empty")
17+
return
18+
}
19+
20+
if len(markdownVars.title) < 1 {
21+
log.L(log.Red, "title can not be empty")
22+
return
23+
}
24+
25+
if len(markdownVars.text) < 1 {
26+
log.L(log.Red, "text can not be empty")
27+
return
28+
}
29+
30+
client := dingtalk.NewClient(rootVars.accessToken, rootVars.secret)
31+
msg := dingtalk.NewMarkdownMessage().
32+
SetMarkdown(markdownVars.title, markdownVars.text).
33+
SetAt(rootVars.atMobiles, rootVars.isAtAll)
34+
if _, err := client.Send(msg); err != nil {
35+
log.L(log.Red, err.Error())
36+
}
37+
},
38+
}
39+
40+
// MarkdownVars struct
41+
type MarkdownVars struct {
42+
title string
43+
text string
44+
}
45+
46+
var markdownVars MarkdownVars
47+
48+
func init() {
49+
rootCmd.AddCommand(markdownCmd)
50+
markdownCmd.Flags().StringVarP(&markdownVars.title, "title", "i", "", "title")
51+
markdownCmd.Flags().StringVarP(&markdownVars.text, "text", "e", "", "text")
52+
}

cmd/dingtalk/root.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dingtalk
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var rootCmd = &cobra.Command{
11+
Use: "dingtalk",
12+
Short: "dingtalk is a command line tool for DingTalk",
13+
Long: "dingtalk is a command line tool for DingTalk",
14+
}
15+
16+
// Execute adds all child commands to the root command and sets flags appropriately.
17+
// This is called by main.main(). It only needs to happen once to the rootCmd.
18+
func Execute() {
19+
if err := rootCmd.Execute(); err != nil {
20+
fmt.Println(err)
21+
os.Exit(1)
22+
}
23+
}
24+
25+
// CheckToken check token
26+
func CheckToken() bool {
27+
return len(rootVars.accessToken) > 0
28+
}
29+
30+
// RootVars struct
31+
type RootVars struct {
32+
accessToken string
33+
secret string
34+
isAtAll bool
35+
atMobiles []string
36+
}
37+
38+
var rootVars RootVars
39+
40+
func init() {
41+
rootCmd.PersistentFlags().StringVarP(&rootVars.accessToken, "token", "t", "", "access_token")
42+
rootCmd.PersistentFlags().StringVarP(&rootVars.secret, "secret", "s", "", "secret")
43+
rootCmd.PersistentFlags().BoolVarP(&rootVars.isAtAll, "isAtAll", "a", false, "isAtAll")
44+
rootCmd.PersistentFlags().StringSliceVarP(&rootVars.atMobiles, "atMobiles", "m", []string{}, "atMobiles")
45+
}

cmd/dingtalk/text.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dingtalk
2+
3+
import (
4+
"github.com/CatchZeng/dingtalk"
5+
"github.com/CatchZeng/gutils/log"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var textCmd = &cobra.Command{
10+
Use: "text",
11+
Short: "send text message with Client robot",
12+
Long: `send text message with Client robot`,
13+
Args: cobra.MinimumNArgs(0),
14+
Run: func(_ *cobra.Command, args []string) {
15+
if !CheckToken() {
16+
log.L(log.Red, "access_token can not be empty")
17+
return
18+
}
19+
20+
if len(textVars.content) < 1 {
21+
log.L(log.Red, "content can not be empty")
22+
return
23+
}
24+
25+
client := dingtalk.NewClient(rootVars.accessToken, rootVars.secret)
26+
msg := dingtalk.NewTextMessage().
27+
SetContent(textVars.content).
28+
SetAt(rootVars.atMobiles, rootVars.isAtAll)
29+
if _, err := client.Send(msg); err != nil {
30+
log.L(log.Red, err.Error())
31+
}
32+
},
33+
}
34+
35+
// TextVars struct
36+
type TextVars struct {
37+
content string
38+
}
39+
40+
var textVars TextVars
41+
42+
func init() {
43+
rootCmd.AddCommand(textCmd)
44+
textCmd.Flags().StringVarP(&textVars.content, "content", "c", "", "content")
45+
}

cmd/dingtalk/version.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dingtalk
2+
3+
import (
4+
"github.com/CatchZeng/dingtalk/internal/version"
5+
"log"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
// versionCmd represents the version command
11+
var versionCmd = &cobra.Command{
12+
Use: "version",
13+
Short: "dingtalk version",
14+
Long: `dingtalk version`,
15+
Run: runVersionCmd,
16+
}
17+
18+
func runVersionCmd(_ *cobra.Command, _ []string) {
19+
v := version.GetVersion()
20+
log.Println(v)
21+
}
22+
23+
func init() {
24+
rootCmd.AddCommand(versionCmd)
25+
}

0 commit comments

Comments
 (0)