github.com/openshift/source-to-image@v1.4.1-0.20240516041539-bf52fc02204e/pkg/cmd/cli/cli.go (about)

     1  package cli
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"runtime"
     7  	"strings"
     8  
     9  	"github.com/spf13/cobra"
    10  
    11  	"github.com/openshift/source-to-image/pkg/api"
    12  	"github.com/openshift/source-to-image/pkg/cmd/cli/cmd"
    13  	cmdutil "github.com/openshift/source-to-image/pkg/cmd/cli/util"
    14  	"github.com/openshift/source-to-image/pkg/docker"
    15  	utillog "github.com/openshift/source-to-image/pkg/util/log"
    16  )
    17  
    18  // log is a placeholder until the builders pass an output stream down
    19  // client facing libraries should not be using log
    20  var log = utillog.StderrLog
    21  
    22  // NewCmdCLI implements the S2I command line functionality.
    23  func NewCmdCLI() *cobra.Command {
    24  	cfg := &api.Config{}
    25  	s2iCmd := &cobra.Command{
    26  		Use: "s2i",
    27  		Long: "Source-to-image (S2I) is a tool for building repeatable docker images.\n\n" +
    28  			"A command line interface that injects and assembles source code into a docker image.\n" +
    29  			"Complete documentation is available at http://github.com/openshift/source-to-image",
    30  		Run: func(cmd *cobra.Command, args []string) {
    31  			cmd.Help()
    32  		},
    33  	}
    34  	cfg.DockerConfig = docker.GetDefaultDockerConfig()
    35  	s2iCmd.PersistentFlags().StringVarP(&(cfg.DockerConfig.Endpoint), "url", "U", cfg.DockerConfig.Endpoint, "Set the url of the docker socket to use")
    36  	s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.CertFile), "cert", cfg.DockerConfig.CertFile, "Set the path of the docker TLS certificate file")
    37  	s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.KeyFile), "key", cfg.DockerConfig.KeyFile, "Set the path of the docker TLS key file")
    38  	s2iCmd.PersistentFlags().StringVar(&(cfg.DockerConfig.CAFile), "ca", cfg.DockerConfig.CAFile, "Set the path of the docker TLS ca file")
    39  	s2iCmd.PersistentFlags().BoolVar(&(cfg.DockerConfig.UseTLS), "tls", cfg.DockerConfig.UseTLS, "Use TLS to connect to docker; implied by --tlsverify")
    40  	s2iCmd.PersistentFlags().BoolVar(&(cfg.DockerConfig.TLSVerify), "tlsverify", cfg.DockerConfig.TLSVerify, "Use TLS to connect to docker and verify the remote")
    41  	s2iCmd.AddCommand(cmd.NewCmdVersion())
    42  	s2iCmd.AddCommand(cmd.NewCmdBuild(cfg))
    43  	s2iCmd.AddCommand(cmd.NewCmdRebuild(cfg))
    44  	s2iCmd.AddCommand(cmd.NewCmdUsage(cfg))
    45  	s2iCmd.AddCommand(cmd.NewCmdCreate())
    46  	s2iCmd.AddCommand(cmd.NewCmdGenerate(cfg))
    47  	cmdutil.SetupLogger(s2iCmd.PersistentFlags())
    48  	basename := filepath.Base(os.Args[0])
    49  	// Make case-insensitive and strip executable suffix if present
    50  	if runtime.GOOS == "windows" {
    51  		basename = strings.ToLower(basename)
    52  		basename = strings.TrimSuffix(basename, ".exe")
    53  	}
    54  	if basename == "sti" {
    55  		log.Warning("sti binary is deprecated, use s2i instead")
    56  	}
    57  
    58  	s2iCmd.AddCommand(cmd.NewCmdCompletion(s2iCmd))
    59  
    60  	return s2iCmd
    61  }
    62  
    63  // CommandFor returns the appropriate command for this base name,
    64  // or the OpenShift CLI command.
    65  func CommandFor() *cobra.Command {
    66  	return NewCmdCLI()
    67  }