github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/cmd/tools/kubectl.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2021-Present The Jackal Authors
     3  
     4  // Package tools contains the CLI commands for Jackal.
     5  package tools
     6  
     7  import (
     8  	"os"
     9  
    10  	"github.com/Racer159/jackal/src/cmd/common"
    11  	"github.com/Racer159/jackal/src/config/lang"
    12  	"github.com/Racer159/jackal/src/pkg/message"
    13  	"github.com/spf13/cobra"
    14  	kubeCLI "k8s.io/component-base/cli"
    15  	kubeCmd "k8s.io/kubectl/pkg/cmd"
    16  
    17  	// Import to initialize client auth plugins.
    18  	_ "k8s.io/client-go/plugin/pkg/client/auth"
    19  )
    20  
    21  func init() {
    22  	// Kubectl stub command.
    23  	kubectlCmd := &cobra.Command{
    24  		Short: lang.CmdToolsKubectlDocs,
    25  		Run:   func(_ *cobra.Command, _ []string) {},
    26  	}
    27  
    28  	// Only load this command if it is being called directly.
    29  	if common.IsVendorCmd(os.Args, []string{"kubectl", "k"}) {
    30  		// Add the kubectl command to the tools command.
    31  		kubectlCmd = kubeCmd.NewDefaultKubectlCommand()
    32  
    33  		if err := kubeCLI.RunNoErrOutput(kubectlCmd); err != nil {
    34  			// @todo(jeff-mccoy) - Kubectl gets mad about being a subcommand.
    35  			message.Debug(err)
    36  		}
    37  	}
    38  
    39  	kubectlCmd.Use = "kubectl"
    40  	kubectlCmd.Aliases = []string{"k"}
    41  
    42  	toolsCmd.AddCommand(kubectlCmd)
    43  }