forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (37 loc) · 873 Bytes
/
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
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/linkerd/linkerd2/cli/cmd"
)
func main() {
root := cmd.RootCmd
args := os.Args[1:]
if _, _, err := root.Find(args); err != nil {
if strings.HasPrefix(args[0], "-") {
fmt.Fprintln(os.Stderr, "Cannot accept flags before Linkerd extension name")
os.Exit(1)
}
path, err := exec.LookPath(fmt.Sprintf("linkerd-%s", args[0]))
if err == nil {
// We're working with a Linkerd plugin at this point which means
// it's up to the plugin to cleanse the arguments if needed.
//nolint:gosec
plugin := exec.Command(path, args[1:]...)
plugin.Stdin = os.Stdin
plugin.Stdout = os.Stdout
plugin.Stderr = os.Stderr
err = plugin.Run()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return
}
}
if err := root.Execute(); err != nil {
os.Exit(1)
}
}