mirror of https://github.com/docker/cli.git
Fix yamldocs outputing `[flags]` in usage output
A similar change was made in the CLI itself, but is not inherited by the code that generates the YAML docs. Before this patch is applied; ``` usage: docker container exec [OPTIONS] CONTAINER COMMAND [ARG...] [flags] ``` With this patch applied: ``` usage: docker container exec [OPTIONS] CONTAINER COMMAND [ARG...] ``` Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f64dc97aca
commit
44d96e9120
|
@ -22,6 +22,7 @@ func generateCliYaml(opts *options) error {
|
||||||
dockerCli := command.NewDockerCli(stdin, stdout, stderr, false, nil)
|
dockerCli := command.NewDockerCli(stdin, stdout, stderr, false, nil)
|
||||||
cmd := &cobra.Command{Use: "docker"}
|
cmd := &cobra.Command{Use: "docker"}
|
||||||
commands.AddCommands(cmd, dockerCli)
|
commands.AddCommands(cmd, dockerCli)
|
||||||
|
disableFlagsInUseLine(cmd)
|
||||||
source := filepath.Join(opts.source, descriptionSourcePath)
|
source := filepath.Join(opts.source, descriptionSourcePath)
|
||||||
if err := loadLongDescription(cmd, source); err != nil {
|
if err := loadLongDescription(cmd, source); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -31,6 +32,23 @@ func generateCliYaml(opts *options) error {
|
||||||
return GenYamlTree(cmd, opts.target)
|
return GenYamlTree(cmd, opts.target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func disableFlagsInUseLine(cmd *cobra.Command) {
|
||||||
|
visitAll(cmd, func(ccmd *cobra.Command) {
|
||||||
|
// do not add a `[flags]` to the end of the usage line.
|
||||||
|
ccmd.DisableFlagsInUseLine = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// visitAll will traverse all commands from the root.
|
||||||
|
// This is different from the VisitAll of cobra.Command where only parents
|
||||||
|
// are checked.
|
||||||
|
func visitAll(root *cobra.Command, fn func(*cobra.Command)) {
|
||||||
|
for _, cmd := range root.Commands() {
|
||||||
|
visitAll(cmd, fn)
|
||||||
|
}
|
||||||
|
fn(root)
|
||||||
|
}
|
||||||
|
|
||||||
func loadLongDescription(cmd *cobra.Command, path ...string) error {
|
func loadLongDescription(cmd *cobra.Command, path ...string) error {
|
||||||
for _, cmd := range cmd.Commands() {
|
for _, cmd := range cmd.Commands() {
|
||||||
if cmd.Name() == "" {
|
if cmd.Name() == "" {
|
||||||
|
|
Loading…
Reference in New Issue