diff --git a/pkg/cmd/cli/cli.go b/pkg/cmd/cli/cli.go index 96b45d83c401..9baafc0708bd 100644 --- a/pkg/cmd/cli/cli.go +++ b/pkg/cmd/cli/cli.go @@ -12,6 +12,7 @@ import ( "github.com/openshift/origin/pkg/cmd/cli/cmd" "github.com/openshift/origin/pkg/cmd/templates" "github.com/openshift/origin/pkg/cmd/util/clientcmd" + "github.com/openshift/origin/pkg/version" ) const longDesc = ` @@ -65,7 +66,6 @@ func NewCommandCLI(name, fullName string) *cobra.Command { cmds.AddCommand(cmd.NewCmdCancelBuild(f, out)) cmds.AddCommand(cmd.NewCmdBuildLogs(f, out)) cmds.AddCommand(cmd.NewCmdRollback(name, "rollback", f, out)) - cmds.AddCommand(cmd.NewCmdGet(fullName, f, out)) cmds.AddCommand(f.NewCmdDescribe(out)) // Deprecate 'osc apply' with 'osc create' command. @@ -73,15 +73,11 @@ func NewCommandCLI(name, fullName string) *cobra.Command { cmds.AddCommand(cmd.NewCmdProcess(f, out)) cmds.AddCommand(cmd.NewCmdUpdate(fullName, f, out)) cmds.AddCommand(cmd.NewCmdDelete(fullName, f, out)) - cmds.AddCommand(cmd.NewCmdLog(fullName, f, out)) cmds.AddCommand(f.NewCmdProxy(out)) - cmds.AddCommand(kubecmd.NewCmdNamespace(out)) - - // Origin build commands - cmds.AddCommand(cmd.NewCmdOptions(f, out)) + cmds.AddCommand(version.NewVersionCommand(name)) return cmds } diff --git a/pkg/cmd/infra/builder/builder.go b/pkg/cmd/infra/builder/builder.go index 6364aca61ebf..15c31f07c1c9 100644 --- a/pkg/cmd/infra/builder/builder.go +++ b/pkg/cmd/infra/builder/builder.go @@ -1,12 +1,11 @@ package builder import ( - "fmt" - "github.com/spf13/cobra" "github.com/openshift/origin/pkg/build/builder/cmd" "github.com/openshift/origin/pkg/cmd/templates" + "github.com/openshift/origin/pkg/version" ) const longCommandSTIDesc = ` @@ -19,7 +18,7 @@ It expects to be run inside of a container. // NewCommandSTIBuilder provides a CLI handler for STI build type func NewCommandSTIBuilder(name string) *cobra.Command { cmd := &cobra.Command{ - Use: fmt.Sprintf("%s", name), + Use: name, Short: "Run an OpenShift Source-to-Images build", Long: longCommandSTIDesc, Run: func(c *cobra.Command, args []string) { @@ -28,6 +27,7 @@ func NewCommandSTIBuilder(name string) *cobra.Command { } cmd.SetUsageTemplate(templates.MainUsageTemplate()) cmd.SetHelpTemplate(templates.MainHelpTemplate()) + cmd.AddCommand(version.NewVersionCommand(name)) return cmd } @@ -41,7 +41,7 @@ It expects to be run inside of a container. // NewCommandDockerBuilder provides a CLI handler for Docker build type func NewCommandDockerBuilder(name string) *cobra.Command { cmd := &cobra.Command{ - Use: fmt.Sprintf("%s", name), + Use: name, Short: "Run an OpenShift Docker build", Long: longCommandDockerDesc, Run: func(c *cobra.Command, args []string) { @@ -50,5 +50,6 @@ func NewCommandDockerBuilder(name string) *cobra.Command { } cmd.SetUsageTemplate(templates.MainUsageTemplate()) cmd.SetHelpTemplate(templates.MainHelpTemplate()) + cmd.AddCommand(version.NewVersionCommand(name)) return cmd } diff --git a/pkg/cmd/infra/deployer/deployer.go b/pkg/cmd/infra/deployer/deployer.go index 575ee18a83fd..8279b59a9079 100644 --- a/pkg/cmd/infra/deployer/deployer.go +++ b/pkg/cmd/infra/deployer/deployer.go @@ -17,6 +17,7 @@ import ( deployapi "github.com/openshift/origin/pkg/deploy/api" strategy "github.com/openshift/origin/pkg/deploy/strategy/recreate" deployutil "github.com/openshift/origin/pkg/deploy/util" + "github.com/openshift/origin/pkg/version" ) const longCommandDesc = ` @@ -68,6 +69,7 @@ func NewCommandDeployer(name string) *cobra.Command { cmd.SetUsageTemplate(templates.MainUsageTemplate()) cmd.SetHelpTemplate(templates.MainHelpTemplate()) + cmd.AddCommand(version.NewVersionCommand(name)) flag := cmd.Flags() cfg.Config.Bind(flag) diff --git a/pkg/cmd/infra/router/router.go b/pkg/cmd/infra/router/router.go index 7e5bf66eecf0..d8737e49c36f 100644 --- a/pkg/cmd/infra/router/router.go +++ b/pkg/cmd/infra/router/router.go @@ -12,6 +12,7 @@ import ( "github.com/openshift/origin/pkg/cmd/util/clientcmd" "github.com/openshift/origin/pkg/router" controllerfactory "github.com/openshift/origin/pkg/router/controller/factory" + "github.com/openshift/origin/pkg/version" templateplugin "github.com/openshift/origin/plugins/router/template" ) @@ -52,6 +53,7 @@ func NewCommandTemplateRouter(name string) *cobra.Command { cmd.SetUsageTemplate(templates.MainUsageTemplate()) cmd.SetHelpTemplate(templates.MainHelpTemplate()) + cmd.AddCommand(version.NewVersionCommand(name)) flag := cmd.Flags() cfg.Config.Bind(flag) diff --git a/pkg/cmd/openshift/openshift.go b/pkg/cmd/openshift/openshift.go index a60870b9de4d..e201fe420244 100644 --- a/pkg/cmd/openshift/openshift.go +++ b/pkg/cmd/openshift/openshift.go @@ -4,7 +4,6 @@ import ( "fmt" "os" - kubeversion "github.com/GoogleCloudPlatform/kubernetes/pkg/version" "github.com/spf13/cobra" "github.com/openshift/origin/pkg/cmd/cli" @@ -85,7 +84,7 @@ func NewCommandOpenShift() *cobra.Command { root.AddCommand(cli.NewCommandCLI("cli", "openshift cli")) root.AddCommand(cli.NewCmdKubectl("kube")) root.AddCommand(newExperimentalCommand("openshift", "ex")) - root.AddCommand(newVersionCommand("version")) + root.AddCommand(version.NewVersionCommand("openshift")) // infra commands are those that are bundled with the binary but not displayed to end users // directly @@ -128,15 +127,3 @@ func newExperimentalCommand(parentName, name string) *cobra.Command { experimental.AddCommand(exregistry.NewCmdRegistry(f, subName, "registry", os.Stdout)) return experimental } - -// newVersionCommand creates a command for displaying the version of this binary -func newVersionCommand(name string) *cobra.Command { - return &cobra.Command{ - Use: name, - Short: "Display version", - Run: func(c *cobra.Command, args []string) { - fmt.Printf("openshift %v\n", version.Get()) - fmt.Printf("kubernetes %v\n", kubeversion.Get()) - }, - } -} diff --git a/pkg/version/version.go b/pkg/version/version.go index ac4502bc3abd..5ac6961368d6 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,5 +1,12 @@ package version +import ( + "fmt" + + kubeversion "github.com/GoogleCloudPlatform/kubernetes/pkg/version" + "github.com/spf13/cobra" +) + var ( // commitFromGit is a constant representing the source version that // generated this build. It should be set during build via -ldflags. @@ -42,3 +49,15 @@ func (info Info) String() string { } return version } + +// NewVersionCommand creates a command for displaying the version of this binary +func NewVersionCommand(basename string) *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "Display version", + Run: func(c *cobra.Command, args []string) { + fmt.Printf("%s %v\n", basename, Get()) + fmt.Printf("kubernetes %v\n", kubeversion.Get()) + }, + } +}