-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
66 lines (53 loc) · 1.25 KB
/
cli.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
package main
import (
"bufio"
"flag"
"fmt"
"io"
"os"
)
const (
appName = "tinygo-autocmpl"
appDescription = ""
)
type cli struct {
outStream io.Writer
errStream io.Writer
}
// Run ...
func (c *cli) Run(args []string) error {
var (
completionScriptBash = flag.Bool("completion-script-bash", false, "print completion-script-bash")
completionScriptZsh = flag.Bool("completion-script-zsh", false, "print completion-script-zsh")
completionScriptClink = flag.Bool("completion-script-clink", false, "print completion-script-clink")
targetsListPath = flag.String("targets", "", "targets list file")
)
flag.Parse()
if *completionScriptBash {
handleCompletionScriptBash(*targetsListPath)
return nil
}
if *completionScriptZsh {
handleCompletionScriptZsh(*targetsListPath)
return nil
}
if *completionScriptClink {
handleCompletionScriptClink(*targetsListPath)
return nil
}
if *targetsListPath != "" {
r, err := os.Open(*targetsListPath)
if err != nil {
return err
}
defer r.Close()
scanner := bufio.NewScanner(r)
targets := []string{}
for scanner.Scan() {
targets = append(targets, scanner.Text())
}
flagCompleteMap["target"] = targets
}
fmt.Printf("%s\n", completionBash(flag.Args()))
return nil
}