-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
122 lines (113 loc) · 2.32 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"fmt"
"log"
"os"
"strings"
"time"
"github.com/urfave/cli"
)
func save(i string) {
// v := convertToStringSlice(i)
// v := convertToStruct(i)
v := convertToMap(i)
v.convertToString()
// print(v)
saveToFile(v)
// shapeMain()
// file_reader()
// checkAnimals()
}
func main() {
// app := &cli.App{
// Name: "JapDic",
// Usage: "saves a jap vocab",
// Action: func(c *cli.Context) error {
// // fmt.Printf("Hello %q", c.Args().Get(0))
// i := c.Args().Get(1)
// // fmt.Println(i)
// save(i)
// return nil
// },
// }
app := &cli.App{
Commands: []*cli.Command{
{
Name: "save",
Aliases: []string{"s"},
Usage: "saves a jap vocab",
Action: func(cCtx *cli.Context) error {
s := ""
for i := 0; i < cCtx.NArg(); i++ {
s += cCtx.Args().Get(i) + " "
}
save(strings.TrimSpace(s))
fmt.Println("saved", s)
return nil
},
},
{
Name: "find",
Aliases: []string{"f"},
Usage: "find a word from the list",
Action: func(cCtx *cli.Context) error {
fmt.Println("Finding word: ", cCtx.Args().First())
line := find(cCtx.Args().First())
if line == "" {
fmt.Println("Nothing found")
} else {
fmt.Println("Found word: ", line)
}
return nil
},
},
{
Name: "read",
Aliases: []string{"r"},
Usage: "read all",
Action: func(cCtx *cli.Context) error {
fmt.Println("showing all...")
lines := readFromFile()
for _, l := range lines {
fmt.Println(l)
}
// fmt.Println(s)
return nil
},
},
{
Name: "translate",
Aliases: []string{"tr"},
Usage: "translate",
Action: func(cCtx *cli.Context) error {
a := cCtx.Args().First()
fmt.Println("Translate word: ", a)
if isJap(a) {
s := translate(a, "ja")
fmt.Println(s)
} else {
s := translate(a, "en")
fmt.Println(s)
}
return nil
},
},
{
Name: "test",
Aliases: []string{"t"},
Usage: "randomly show 1 jap or eng word",
Action: func(cCtx *cli.Context) error {
s := readFromFile()
r1, r2 := randomVocab(s)
fmt.Println(r1)
time.Sleep(8 * time.Second)
fmt.Println(r2)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}