From 669397c81cedd658eef9afb41b4604a7d06c9877 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 4 Nov 2021 13:39:10 +0100 Subject: [PATCH] always disable the addition of [flags] to the usage Signed-off-by: CrazyMax --- clidocstool.go | 19 ------------------- clidocstool_md.go | 3 +++ clidocstool_yaml.go | 3 +++ example/main.go | 1 - fixtures/docker_buildx_build.yaml | 2 +- fixtures/docker_buildx_stop.yaml | 2 +- 6 files changed, 8 insertions(+), 22 deletions(-) diff --git a/clidocstool.go b/clidocstool.go index 484e6db..79a44a1 100644 --- a/clidocstool.go +++ b/clidocstool.go @@ -80,25 +80,6 @@ func (c *Client) GenAllTree() error { return nil } -// DisableFlagsInUseLine sets the DisableFlagsInUseLine flag on all -// commands within the tree rooted at cmd. -func (c *Client) DisableFlagsInUseLine() { - visitAll(c.root, func(ccmd *cobra.Command) { - // do not add a `[flags]` to the end of the usage line. - ccmd.DisableFlagsInUseLine = true - }) -} - -// visitAll traverses 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 fileExists(f string) bool { info, err := os.Stat(f) if os.IsNotExist(err) { diff --git a/clidocstool_md.go b/clidocstool_md.go index 74b27a7..7b1d6ec 100644 --- a/clidocstool_md.go +++ b/clidocstool_md.go @@ -37,6 +37,9 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error { } } + // always disable the addition of [flags] to the usage + cmd.DisableFlagsInUseLine = true + // Skip the root command altogether, to prevent generating a useless // md file for plugins. if c.plugin && !cmd.HasParent() { diff --git a/clidocstool_yaml.go b/clidocstool_yaml.go index d2923d5..91ccf62 100644 --- a/clidocstool_yaml.go +++ b/clidocstool_yaml.go @@ -97,6 +97,9 @@ func (c *Client) genYamlTreeCustom(cmd *cobra.Command, filePrepender func(string } } + // always disable the addition of [flags] to the usage + cmd.DisableFlagsInUseLine = true + // The "root" command used in the generator is just a "stub", and only has a // list of subcommands, but not (e.g.) global options/flags. We should fix // that, so that the YAML file for the docker "root" command contains the diff --git a/example/main.go b/example/main.go index 0a5b93e..0af4516 100644 --- a/example/main.go +++ b/example/main.go @@ -63,7 +63,6 @@ func gen(opts *options) error { if err != nil { return err } - c.DisableFlagsInUseLine() // generate all supported docs formats return c.GenAllTree() diff --git a/fixtures/docker_buildx_build.yaml b/fixtures/docker_buildx_build.yaml index b904a72..328a846 100644 --- a/fixtures/docker_buildx_build.yaml +++ b/fixtures/docker_buildx_build.yaml @@ -2,7 +2,7 @@ command: docker buildx build aliases: b short: Start a build long: Start a build -usage: docker buildx build [OPTIONS] PATH | URL | - [flags] +usage: docker buildx build [OPTIONS] PATH | URL | - pname: docker buildx plink: docker_buildx.yaml options: diff --git a/fixtures/docker_buildx_stop.yaml b/fixtures/docker_buildx_stop.yaml index 93f6fa2..4e74ff7 100644 --- a/fixtures/docker_buildx_stop.yaml +++ b/fixtures/docker_buildx_stop.yaml @@ -1,7 +1,7 @@ command: docker buildx stop short: Stop builder instance long: Stop builder instance -usage: docker buildx stop [NAME] [flags] +usage: docker buildx stop [NAME] pname: docker buildx plink: docker_buildx.yaml inherited_options: