-
Notifications
You must be signed in to change notification settings - Fork 42
/
gen_emoji_codeMap.go
96 lines (83 loc) · 2.46 KB
/
gen_emoji_codeMap.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
package builtin
import (
"fmt"
"github.com/gookit/cliapp"
"io"
"net/http"
"os"
"time"
)
type genEmojiMap struct {
c *cliapp.Command
// muan - https://raw.githubusercontent.com/muan/emoji/gh-pages/javascripts/emojilib/emojis.json
// gemoji - https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json
// unicode - https://unicode.org/Public/emoji/11.0/emoji-test.txt
source string // allow: gemoji
saveDir string
onlyGen bool
}
type Gemoji struct {
Aliases []string `json:"aliases"`
Description string `json:"description"`
Emoji string `json:"emoji"`
Tags []string `json:"tags"`
}
// GenEmojiMapCommand create
func GenEmojiMapCommand() *cliapp.Command {
gem := &genEmojiMap{}
return &cliapp.Command{
Name: "gen:emojis",
Aliases: []string{"gen:emoji", "gen:emj"},
// handler func
Func: gem.run,
// des
UseFor: "fetch emoji codes form data source url, then generate a go file.",
// config options
Config: func(c *cliapp.Command) {
gem.c = c
c.StrOpt(
&gem.source, "source", "s", "gemoji",
"the emoji data source, allow: muan, gemoji, unicode",
)
c.StrOpt(&gem.saveDir, "dir", "d", "./", "the generated go file save `DIR` path")
c.BoolOpt(&gem.onlyGen, "onlyGen", "", false, "whether only generate go file from exists emoji data file")
},
Help: `source allow:
muan - https://raw.githubusercontent.com/muan/emoji/gh-pages/javascripts/emojilib/emojis.json
gemoji - https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json
unicode - https://unicode.org/Public/emoji/11.0/emoji-test.txt
`,
}
}
func (g *genEmojiMap) run(c *cliapp.Command, _ []string) int {
return 0
}
// 实现单个文件的下载
func (g *genEmojiMap) Download(remoteFile string, saveAs string) error {
nt := time.Now().Format("2006-01-02 15:04:05")
fmt.Printf("[%s]To download %s\n", nt, remoteFile)
newFile, err := os.Create(saveAs)
if err != nil {
return err
}
defer newFile.Close()
client := http.Client{Timeout: 900 * time.Second}
resp, err := client.Get(remoteFile)
defer resp.Body.Close()
_, err = io.Copy(newFile, resp.Body)
if err != nil {
fmt.Println(err.Error())
}
return nil
}
const templateString = `
package {{.PkgName}}
// NOTE: THIS FILE WAS PRODUCED BY THE
// EMOJI COD EMAP CODE GENERATION TOOL (https://github.com/gookit/cliapp)
// DO NOT EDIT
// Mapping from character to concrete escape code.
var emojiMap = map[string]string{
{{range $key, $val := .CodeMap}}":{{$key}}:": {{$val}},
{{end}}
}
`