Skip to content

Commit bb7d7e4

Browse files
committed
skip hidden command recursively
Signed-off-by: CrazyMax <[email protected]>
1 parent b6c6689 commit bb7d7e4

File tree

7 files changed

+114
-33
lines changed

7 files changed

+114
-33
lines changed

clidocstool_man.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ func (c *Client) genManTreeCustom(cmd *cobra.Command) error {
6464
return nil
6565
}
6666

67+
// Skip hidden command recursively
68+
for curr := cmd; curr != nil; curr = curr.Parent() {
69+
if curr.Hidden {
70+
log.Printf("INFO: Skipping Man for %q (hidden command)", curr.CommandPath())
71+
return nil
72+
}
73+
}
74+
6775
log.Printf("INFO: Generating Man for %q", cmd.CommandPath())
6876

6977
return doc.GenManTreeFromOpts(cmd, doc.GenManTreeOptions{

clidocstool_md.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error {
5353
return nil
5454
}
5555

56-
// Skip hidden command
57-
if cmd.Hidden {
58-
log.Printf("INFO: Skipping Markdown for %q (hidden command)", cmd.CommandPath())
59-
return nil
56+
// Skip hidden command recursively
57+
for curr := cmd; curr != nil; curr = curr.Parent() {
58+
if curr.Hidden {
59+
log.Printf("INFO: Skipping Markdown for %q (hidden command)", curr.CommandPath())
60+
return nil
61+
}
6062
}
6163

6264
log.Printf("INFO: Generating Markdown for %q", cmd.CommandPath())

clidocstool_test.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ import (
3232
)
3333

3434
var (
35-
dockerCmd *cobra.Command
36-
attachCmd *cobra.Command
37-
buildxCmd *cobra.Command
38-
buildxBuildCmd *cobra.Command
39-
buildxDialStdioCmd *cobra.Command
40-
buildxInstallCmd *cobra.Command
41-
buildxStopCmd *cobra.Command
35+
dockerCmd *cobra.Command
36+
attachCmd *cobra.Command
37+
buildxCmd *cobra.Command
38+
buildxBuildCmd *cobra.Command
39+
buildxDialStdioCmd *cobra.Command
40+
buildxImagetoolsCmd *cobra.Command
41+
buildxImagetoolsCreateCmd *cobra.Command
42+
buildxInstallCmd *cobra.Command
43+
buildxStopCmd *cobra.Command
4244
)
4345

4446
//nolint:errcheck
@@ -97,6 +99,17 @@ func setup() {
9799
Args: cobra.NoArgs,
98100
Run: func(*cobra.Command, []string) {},
99101
}
102+
buildxImagetoolsCmd = &cobra.Command{
103+
Use: "imagetools",
104+
Short: "Commands to work on images in registry",
105+
Run: func(*cobra.Command, []string) {},
106+
Hidden: true,
107+
}
108+
buildxImagetoolsCreateCmd = &cobra.Command{
109+
Use: "create [OPTIONS] [SOURCE...]",
110+
Short: "Create a new image based on source images",
111+
Run: func(*cobra.Command, []string) {},
112+
}
100113
buildxInstallCmd = &cobra.Command{
101114
Use: "install",
102115
Short: "Install buildx as a 'docker builder' alias",
@@ -223,6 +236,8 @@ format: "default|<id>[=<socket>|<key>[,<key>]]"`)
223236

224237
buildxCmd.AddCommand(buildxBuildCmd)
225238
buildxCmd.AddCommand(buildxDialStdioCmd)
239+
buildxImagetoolsCmd.AddCommand(buildxImagetoolsCreateCmd)
240+
buildxCmd.AddCommand(buildxImagetoolsCmd)
226241
buildxCmd.AddCommand(buildxInstallCmd)
227242
buildxCmd.AddCommand(buildxStopCmd)
228243
dockerCmd.AddCommand(buildxCmd)
@@ -233,6 +248,11 @@ func TestGenAllTree(t *testing.T) {
233248
setup()
234249
tmpdir := t.TempDir()
235250

251+
// keep for testing
252+
//tmpdir, err := os.MkdirTemp("", "cli-docs-tools")
253+
//require.NoError(t, err)
254+
//t.Log(tmpdir)
255+
236256
epoch, err := time.Parse("2006-Jan-02", "2020-Jan-10")
237257
require.NoError(t, err)
238258
t.Setenv("SOURCE_DATE_EPOCH", strconv.FormatInt(epoch.Unix(), 10))

clidocstool_yaml.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ func (c *Client) genYamlCustom(cmd *cobra.Command, w io.Writer) error {
169169

170170
// check recursively to handle inherited annotations
171171
for curr := cmd; curr != nil; curr = curr.Parent() {
172+
if curr.Hidden {
173+
cliDoc.Hidden = true
174+
}
172175
if v, ok := curr.Annotations["version"]; ok && cliDoc.MinAPIVersion == "" {
173176
cliDoc.MinAPIVersion = v
174177
}

fixtures/docker-buildx-install.1

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
command: docker buildx imagetools
2+
short: Commands to work on images in registry
3+
long: Commands to work on images in registry
4+
usage: docker buildx imagetools
5+
pname: docker buildx
6+
plink: docker_buildx.yaml
7+
cname:
8+
- docker buildx imagetools create
9+
clink:
10+
- docker_buildx_imagetools_create.yaml
11+
inherited_options:
12+
- option: builder
13+
value_type: string
14+
description: Override the configured builder instance
15+
deprecated: false
16+
hidden: false
17+
experimental: false
18+
experimentalcli: false
19+
kubernetes: false
20+
swarm: false
21+
- option: help
22+
value_type: bool
23+
default_value: "false"
24+
description: Print usage
25+
deprecated: false
26+
hidden: true
27+
experimental: false
28+
experimentalcli: false
29+
kubernetes: false
30+
swarm: false
31+
deprecated: false
32+
hidden: true
33+
experimental: false
34+
experimentalcli: false
35+
kubernetes: false
36+
swarm: false
37+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
command: docker buildx imagetools create
2+
short: Create a new image based on source images
3+
long: Create a new image based on source images
4+
usage: docker buildx imagetools create [OPTIONS] [SOURCE...]
5+
pname: docker buildx imagetools
6+
plink: docker_buildx_imagetools.yaml
7+
inherited_options:
8+
- option: builder
9+
value_type: string
10+
description: Override the configured builder instance
11+
deprecated: false
12+
hidden: false
13+
experimental: false
14+
experimentalcli: false
15+
kubernetes: false
16+
swarm: false
17+
- option: help
18+
value_type: bool
19+
default_value: "false"
20+
description: Print usage
21+
deprecated: false
22+
hidden: true
23+
experimental: false
24+
experimentalcli: false
25+
kubernetes: false
26+
swarm: false
27+
deprecated: false
28+
hidden: true
29+
experimental: false
30+
experimentalcli: false
31+
kubernetes: false
32+
swarm: false
33+

0 commit comments

Comments
 (0)