-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
64 lines (53 loc) · 1.38 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/atotto/clipboard"
"github.com/kyokomi/emoji/v2"
"github.com/urfave/cli/v2"
)
func main() {
useClipboard := false
app := &cli.App{
Name: "emojiterm - text to emoji converter - Use underscore instead of space in emoji names",
Usage: "emojiterm \"<space separeted list of tokens>\" | Example: emojiterm \"sun wine_glass beer)\"\n" +
"Names are based on this file: https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "clipboard",
Aliases: []string{"c"},
Usage: "write emojis to clipboard",
DisableDefaultText: true,
Action: func(cCtx *cli.Context, b bool) error {
useClipboard = b
return nil
},
},
},
Action: func(cCtx *cli.Context) error {
s := printEmojiArgsAsString(cCtx.Args().Slice())
fmt.Println(s)
if useClipboard {
if err := clipboard.WriteAll(s); err != nil {
fmt.Printf("Clipboard not supported: %v\n", err)
}
}
return nil
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func printEmojiArgsAsString(args []string) string {
emojisAsString := ""
for index, arg := range args {
if index == 0 {
emojisAsString += emoji.Sprintf(":%s:", arg)
} else {
emojisAsString += emoji.Sprintf(" :%s:", arg)
}
}
return emojisAsString
}