mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Wrap output of docker cli --help
This should go some way to unblocking a solution to #18797, #18385 etc by removing the current rather restrictive constraints on help text length. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
parent
a6e536e415
commit
a4f71ccff6
2 changed files with 11 additions and 9 deletions
12
cli/cobra.go
12
cli/cobra.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -14,6 +15,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {
|
|||
cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
|
||||
cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
|
||||
cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)
|
||||
cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
|
||||
|
||||
rootCmd.SetUsageTemplate(usageTemplate)
|
||||
rootCmd.SetHelpTemplate(helpTemplate)
|
||||
|
@ -76,6 +78,14 @@ func operationSubCommands(cmd *cobra.Command) []*cobra.Command {
|
|||
return cmds
|
||||
}
|
||||
|
||||
func wrappedFlagUsages(cmd *cobra.Command) string {
|
||||
width := 80
|
||||
if ws, err := term.GetWinsize(0); err == nil {
|
||||
width = int(ws.Width)
|
||||
}
|
||||
return cmd.Flags().FlagUsagesWrapped(width - 1)
|
||||
}
|
||||
|
||||
func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
|
||||
cmds := []*cobra.Command{}
|
||||
for _, sub := range cmd.Commands() {
|
||||
|
@ -108,7 +118,7 @@ Examples:
|
|||
{{- if .HasFlags}}
|
||||
|
||||
Options:
|
||||
{{.Flags.FlagUsages | trimRightSpace}}
|
||||
{{ wrappedFlagUsages . | trimRightSpace}}
|
||||
|
||||
{{- end}}
|
||||
{{- if hasManagementSubCommands . }}
|
||||
|
|
|
@ -235,14 +235,6 @@ func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) er
|
|||
return fmt.Errorf("Help for %q should not have used ~:\n%s", cmd, line)
|
||||
}
|
||||
|
||||
// If a line starts with 4 spaces then assume someone
|
||||
// added a multi-line description for an option and we need
|
||||
// to flag it
|
||||
if strings.HasPrefix(line, " ") &&
|
||||
!strings.HasPrefix(strings.TrimLeft(line, " "), "--") {
|
||||
return fmt.Errorf("Help for %q should not have a multi-line option", cmd)
|
||||
}
|
||||
|
||||
// Options should NOT end with a period
|
||||
if strings.HasPrefix(line, " -") && strings.HasSuffix(line, ".") {
|
||||
return fmt.Errorf("Help for %q should not end with a period: %s", cmd, line)
|
||||
|
|
Loading…
Reference in a new issue