-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
113 lines (99 loc) · 2.05 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
package main
import (
_ "embed"
"fmt"
"log"
"os"
"time"
"github.com/urfave/cli/v2"
pmy "github.com/relastle/pmy/src"
)
var (
bufferLeft string
bufferRight string
)
//go:embed _shell/_pmy.zsh
var initScript string
func mainRoutine() {
outString := pmy.Run(
pmy.Input{
BufferLeft: bufferLeft,
BufferRight: bufferRight,
},
)
fmt.Println(outString)
}
func initCmdRoutine() {
fmt.Printf("%s", initScript)
}
func ruleListCmdRoutine() {
ruleFiles := pmy.GetAllRuleFiles()
for _, ruleFile := range ruleFiles {
fmt.Println(ruleFile.Path)
}
}
func snippetListCmdRoutine() {
snippetFiles := pmy.GetAllSnippetFiles()
for _, snippetFile := range snippetFiles {
fmt.Println(snippetFile.Path)
}
}
func main() {
pmy.SetConfigs()
start := time.Now()
app := cli.NewApp()
app.Version = "0.7.0"
app.Commands = []*cli.Command{
{
Name: "main",
Usage: "Run main task of pmy. It dumps zsh script necessary to invoke fuzzy finder with appropriate source and edit current zsh line.",
Action: func(c *cli.Context) error {
mainRoutine()
return nil
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "buffer-left, l",
Usage: "Current `left` buffer of zsh line",
Destination: &bufferLeft,
Required: true,
},
&cli.StringFlag{
Name: "buffer-right, r",
Usage: "Current `right` buffer of zsh line",
Destination: &bufferRight,
Required: true,
},
},
},
{
Name: "init",
Usage: "Dump zsh script to be sourced in order to activate pmy.",
Action: func(c *cli.Context) error {
initCmdRoutine()
return nil
},
},
{
Name: "rule-list",
Usage: "List all rule files loaded.",
Action: func(c *cli.Context) error {
ruleListCmdRoutine()
return nil
},
},
{
Name: "snippet-list",
Usage: "List all snippet files loaded.",
Action: func(c *cli.Context) error {
snippetListCmdRoutine()
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
pmy.MeasureElapsedTime(start, "cli arg parse")
}