Skip to content

Commit 669397c

Browse files
committed
always disable the addition of [flags] to the usage
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent e9f8b8c commit 669397c

6 files changed

Lines changed: 8 additions & 22 deletions

File tree

clidocstool.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,6 @@ func (c *Client) GenAllTree() error {
8080
return nil
8181
}
8282

83-
// DisableFlagsInUseLine sets the DisableFlagsInUseLine flag on all
84-
// commands within the tree rooted at cmd.
85-
func (c *Client) DisableFlagsInUseLine() {
86-
visitAll(c.root, func(ccmd *cobra.Command) {
87-
// do not add a `[flags]` to the end of the usage line.
88-
ccmd.DisableFlagsInUseLine = true
89-
})
90-
}
91-
92-
// visitAll traverses all commands from the root.
93-
// This is different from the VisitAll of cobra.Command where only parents
94-
// are checked.
95-
func visitAll(root *cobra.Command, fn func(*cobra.Command)) {
96-
for _, cmd := range root.Commands() {
97-
visitAll(cmd, fn)
98-
}
99-
fn(root)
100-
}
101-
10283
func fileExists(f string) bool {
10384
info, err := os.Stat(f)
10485
if os.IsNotExist(err) {

clidocstool_md.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error {
3737
}
3838
}
3939

40+
// always disable the addition of [flags] to the usage
41+
cmd.DisableFlagsInUseLine = true
42+
4043
// Skip the root command altogether, to prevent generating a useless
4144
// md file for plugins.
4245
if c.plugin && !cmd.HasParent() {

clidocstool_yaml.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (c *Client) genYamlTreeCustom(cmd *cobra.Command, filePrepender func(string
9797
}
9898
}
9999

100+
// always disable the addition of [flags] to the usage
101+
cmd.DisableFlagsInUseLine = true
102+
100103
// The "root" command used in the generator is just a "stub", and only has a
101104
// list of subcommands, but not (e.g.) global options/flags. We should fix
102105
// that, so that the YAML file for the docker "root" command contains the

example/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func gen(opts *options) error {
6363
if err != nil {
6464
return err
6565
}
66-
c.DisableFlagsInUseLine()
6766

6867
// generate all supported docs formats
6968
return c.GenAllTree()

fixtures/docker_buildx_build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ command: docker buildx build
22
aliases: b
33
short: Start a build
44
long: Start a build
5-
usage: docker buildx build [OPTIONS] PATH | URL | - [flags]
5+
usage: docker buildx build [OPTIONS] PATH | URL | -
66
pname: docker buildx
77
plink: docker_buildx.yaml
88
options:

fixtures/docker_buildx_stop.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
command: docker buildx stop
22
short: Stop builder instance
33
long: Stop builder instance
4-
usage: docker buildx stop [NAME] [flags]
4+
usage: docker buildx stop [NAME]
55
pname: docker buildx
66
plink: docker_buildx.yaml
77
inherited_options:

0 commit comments

Comments
 (0)