...

Source file src/github.com/linkerd/linkerd2/cli/main.go

Documentation: github.com/linkerd/linkerd2/cli

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/exec"
     7  	"strings"
     8  
     9  	"github.com/linkerd/linkerd2/cli/cmd"
    10  )
    11  
    12  func main() {
    13  	root := cmd.RootCmd
    14  	args := os.Args[1:]
    15  	if _, _, err := root.Find(args); err != nil {
    16  		if strings.HasPrefix(args[0], "-") {
    17  			fmt.Fprintln(os.Stderr, "Cannot accept flags before Linkerd extension name")
    18  			os.Exit(1)
    19  		}
    20  		path, err := exec.LookPath(fmt.Sprintf("linkerd-%s", args[0]))
    21  		if err == nil {
    22  			// We're working with a Linkerd plugin at this point which means
    23  			// it's up to the plugin to cleanse the arguments if needed.
    24  			//nolint:gosec
    25  			plugin := exec.Command(path, args[1:]...)
    26  			plugin.Stdin = os.Stdin
    27  			plugin.Stdout = os.Stdout
    28  			plugin.Stderr = os.Stderr
    29  			err = plugin.Run()
    30  			if err != nil {
    31  				fmt.Fprintln(os.Stderr, err)
    32  				os.Exit(1)
    33  			}
    34  			return
    35  		}
    36  	}
    37  	if err := root.Execute(); err != nil {
    38  		os.Exit(1)
    39  	}
    40  }
    41  

View as plain text