-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.go
70 lines (59 loc) · 1.3 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
//go:generate node cli/passthrough.js
package main
import (
"os"
"os/exec"
"path"
"strings"
"syscall"
"github.com/kardianos/osext"
"github.com/urfave/cli"
"github.com/arigatomachine/cli/cmd"
"github.com/arigatomachine/cli/config"
)
func main() {
cli.VersionPrinter = func(ctx *cli.Context) {
cmd.VersionLookup(ctx)
}
app := cli.NewApp()
app.Version = config.Version
app.Usage = "A secure, shared workspace for secrets"
app.Commands = cmd.Cmds
app.Run(os.Args)
}
func passthrough(ctx *cli.Context, prefixLen int, slug string) error {
dir, err := osext.ExecutableFolder()
if err != nil {
return err
}
node := path.Join(dir, "ag-node")
args := []string{slug}
for _, f := range ctx.Command.Flags {
name := strings.SplitN(f.GetName(), ", ", 2)[0]
switch f.(type) {
case cli.BoolFlag:
v := ctx.Bool(name)
if v {
args = append(args, "--"+name)
}
default:
v := ctx.String(name)
if v != "" {
args = append(args, "--"+name+"="+v)
}
}
}
args = append(args, ctx.Args()...)
cmd := exec.Command(node, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
os.Exit(status.ExitStatus())
return nil
}
}
return err
}