Skip to content

Commit

Permalink
Merge pull request #890 from fabianofranz/fix_more_help_issues
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Feb 5, 2015
2 parents 693fe49 + b17c2ae commit 4607303
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 26 deletions.
7 changes: 7 additions & 0 deletions pkg/cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/pflag"

"github.com/openshift/origin/pkg/cmd/cli/cmd"
"github.com/openshift/origin/pkg/cmd/templates"
)

const longDesc = `
Expand Down Expand Up @@ -50,6 +51,10 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
f := cmd.NewFactory(clientConfig)
f.BindFlags(cmds.PersistentFlags())
out := os.Stdout

cmds.SetUsageTemplate(templates.CliUsageTemplate)
cmds.SetHelpTemplate(templates.CliHelpTemplate)

// Kubernetes CRUD commands
cmds.AddCommand(f.NewCmdGet(out))
cmds.AddCommand(f.NewCmdDescribe(out))
Expand All @@ -74,6 +79,8 @@ func NewCommandCLI(name, fullName string) *cobra.Command {

cmds.AddCommand(cmd.NewCmdRollback(name, "rollback", f, out))

cmds.AddCommand(cmd.NewCmdOptions(f, out))

return cmds
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/cmd/cli/cmd/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"io"

"github.com/openshift/origin/pkg/cmd/templates"
"github.com/spf13/cobra"
)

func NewCmdOptions(f *Factory, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "options",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

cmd.SetUsageTemplate(templates.OptionsUsageTemplate)
cmd.SetHelpTemplate("")

return cmd
}
11 changes: 9 additions & 2 deletions pkg/cmd/infra/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/build/builder/cmd"
"github.com/openshift/origin/pkg/cmd/templates"
)

const longCommandSTIDesc = `
Expand All @@ -17,14 +18,17 @@ It expects to be run inside of a container.

// NewCommandSTIBuilder provides a CLI handler for STI build type
func NewCommandSTIBuilder(name string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: fmt.Sprintf("%s", name),
Short: "Run an OpenShift Source-to-Images build",
Long: longCommandSTIDesc,
Run: func(c *cobra.Command, args []string) {
cmd.RunSTIBuild()
},
}
cmd.SetUsageTemplate(templates.MainUsageTemplate)
cmd.SetHelpTemplate(templates.MainHelpTemplate)
return cmd
}

const longCommandDockerDesc = `
Expand All @@ -36,12 +40,15 @@ It expects to be run inside of a container.

// NewCommandDockerBuilder provides a CLI handler for Docker build type
func NewCommandDockerBuilder(name string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: fmt.Sprintf("%s", name),
Short: "Run an OpenShift Docker build",
Long: longCommandDockerDesc,
Run: func(c *cobra.Command, args []string) {
cmd.RunDockerBuild()
},
}
cmd.SetUsageTemplate(templates.MainUsageTemplate)
cmd.SetHelpTemplate(templates.MainHelpTemplate)
return cmd
}
4 changes: 4 additions & 0 deletions pkg/cmd/infra/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"

"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
deployapi "github.com/openshift/origin/pkg/deploy/api"
Expand Down Expand Up @@ -66,6 +67,9 @@ func NewCommandDeployer(name string) *cobra.Command {
},
}

cmd.SetUsageTemplate(templates.MainUsageTemplate)
cmd.SetHelpTemplate(templates.MainHelpTemplate)

flag := cmd.Flags()
cfg.Config.Bind(flag)
flag.StringVar(&cfg.DeploymentName, "deployment", util.Env("OPENSHIFT_DEPLOYMENT_NAME", ""), "The deployment name to start")
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/infra/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/golang/glog"
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/router"
Expand Down Expand Up @@ -49,6 +50,9 @@ func NewCommandTemplateRouter(name string) *cobra.Command {
},
}

cmd.SetUsageTemplate(templates.MainUsageTemplate)
cmd.SetHelpTemplate(templates.MainHelpTemplate)

flag := cmd.Flags()
cfg.Config.Bind(flag)
flag.StringVar(&cfg.TemplateFile, "template", util.Env("TEMPLATE_FILE", ""), "The path to the template file to use")
Expand Down
8 changes: 5 additions & 3 deletions pkg/cmd/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/openshift/origin/pkg/cmd/infra/deployer"
"github.com/openshift/origin/pkg/cmd/infra/router"
"github.com/openshift/origin/pkg/cmd/server"
"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/version"
)

Expand Down Expand Up @@ -58,9 +59,6 @@ func CommandFor(basename string) *cobra.Command {
cmd = NewCommandOpenShift()
}

cmd.SetUsageTemplate(usageTemplate)
cmd.SetHelpTemplate(helpTemplate)

flagtypes.GLog(cmd.PersistentFlags())

return cmd
Expand All @@ -78,6 +76,9 @@ func NewCommandOpenShift() *cobra.Command {
},
}

root.SetUsageTemplate(templates.MainUsageTemplate)
root.SetHelpTemplate(templates.MainHelpTemplate)

root.AddCommand(server.NewCommandStartServer("start"))
root.AddCommand(cli.NewCommandCLI("cli", "openshift cli"))
root.AddCommand(cli.NewCmdKubectl("kube"))
Expand All @@ -89,6 +90,7 @@ func NewCommandOpenShift() *cobra.Command {
infra := &cobra.Command{
Use: "infra", // Because this command exposes no description, it will not be shown in help
}

infra.AddCommand(
router.NewCommandTemplateRouter("router"),
deployer.NewCommandDeployer("deploy"),
Expand Down
21 changes: 0 additions & 21 deletions pkg/cmd/openshift/templates.go

This file was deleted.

40 changes: 40 additions & 0 deletions pkg/cmd/templates/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package templates

const (
MainHelpTemplate = `{{.Long | trim}}
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}
`

MainUsageTemplate = `{{ $cmd := . }}
Usage: {{if .Runnable}}
{{.UseLine}}{{if .HasFlags}} [options]{{end}}{{end}}{{if .HasSubCommands}}
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
Aliases:
{{.NameAndAliases}}{{end}}
{{ if .HasSubCommands}}
Available Commands: {{range .Commands}}{{if .Runnable}}
{{rpad .Use .UsagePadding }} {{.Short}}{{end}}{{end}}
{{end}}
{{ if .HasLocalFlags}}Options:
{{.LocalFlags.FlagUsages}}{{end}}
{{ if .HasAnyPersistentFlags}}Global Options:
{{.AllPersistentFlags.FlagUsages}}{{end}}{{ if .HasSubCommands }}
Use "{{.Root.Name}} help [command]" for more information about that command.{{end}}`

CliHelpTemplate = `{{.Long | trim}}
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}
`
CliUsageTemplate = `{{ $cmd := . }}{{ if .HasSubCommands}}
Available Commands: {{range .Commands}}{{if .Runnable}}{{if ne .Name "options"}}
{{rpad .Use .UsagePadding }} {{.Short}}{{end}}{{end}}{{end}}
{{end}}
{{ if .HasLocalFlags}}Options:
{{.LocalFlags.FlagUsages}}{{end}}{{ if .HasSubCommands }}
Use "{{.Root.Name}} help [command]" for more information about that command.{{end}}{{ if .HasAnyPersistentFlags}}
Use "{{.Root.Name}} options" for a list of global command-line options.{{end}}`

OptionsUsageTemplate = `{{ if .HasAnyPersistentFlags}}The following options can be passed to any command:
{{.AllPersistentFlags.FlagUsages}}{{end}}`
)

0 comments on commit 4607303

Please sign in to comment.