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