1
0
mirror of https://github.com/docker/cli-docs-tool.git synced 2025-08-08 10:22:04 +03:00

always disable the addition of [flags] to the usage

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-11-04 13:39:10 +01:00
parent e9f8b8c6e3
commit 669397c81c
6 changed files with 8 additions and 22 deletions

View File

@@ -80,25 +80,6 @@ func (c *Client) GenAllTree() error {
return nil 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 { func fileExists(f string) bool {
info, err := os.Stat(f) info, err := os.Stat(f)
if os.IsNotExist(err) { if os.IsNotExist(err) {

View File

@@ -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 // Skip the root command altogether, to prevent generating a useless
// md file for plugins. // md file for plugins.
if c.plugin && !cmd.HasParent() { if c.plugin && !cmd.HasParent() {

View File

@@ -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 // 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 // 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 // that, so that the YAML file for the docker "root" command contains the

View File

@@ -63,7 +63,6 @@ func gen(opts *options) error {
if err != nil { if err != nil {
return err return err
} }
c.DisableFlagsInUseLine()
// generate all supported docs formats // generate all supported docs formats
return c.GenAllTree() return c.GenAllTree()

View File

@@ -2,7 +2,7 @@ command: docker buildx build
aliases: b aliases: b
short: Start a build short: Start a build
long: 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 pname: docker buildx
plink: docker_buildx.yaml plink: docker_buildx.yaml
options: options:

View File

@@ -1,7 +1,7 @@
command: docker buildx stop command: docker buildx stop
short: Stop builder instance short: Stop builder instance
long: Stop builder instance long: Stop builder instance
usage: docker buildx stop [NAME] [flags] usage: docker buildx stop [NAME]
pname: docker buildx pname: docker buildx
plink: docker_buildx.yaml plink: docker_buildx.yaml
inherited_options: inherited_options: