-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.12 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
package main
import (
"flag"
"fmt"
"log"
"strings"
"github.com/Huweicai/common-decoder/alfred"
"github.com/Huweicai/common-decoder/decoder"
)
func init() {
log.SetFlags(log.Lshortfile | log.Ldate)
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) <= 1 {
panic("too few arguments")
}
var output *alfred.Output
arg := strings.Join(args[1:], " ")
switch args[0] {
case "decode":
output = decode(arg)
case "encode":
output = encode(arg)
}
if output == nil || len(output.Items) == 0 {
output = alfred.NewOutput()
output.AddSimpleTip("Nothing Found", "Nothing Found", "", "")
}
output.Show()
}
func decode(text string) *alfred.Output {
results := decoder.Decode(text)
otp := alfred.NewOutput()
for _, result := range results.Data {
str := fmt.Sprintf("%v", result.Result)
otp.AddSimpleTip(str, result.DecoderName, str, "")
}
return otp
}
func encode(text string) *alfred.Output {
results := decoder.Encode(text)
otp := alfred.NewOutput()
for _, result := range results.Data {
str := fmt.Sprintf("%v", result.Result)
otp.AddSimpleTip(str, result.DecoderName, str, "")
}
return otp
}