Skip to content

Commit 5cb124c

Browse files
authored
Merge pull request #38 from crazy-max/missing-hidden
Take hidden attribute into account
2 parents ce91c05 + 851d1b7 commit 5cb124c

8 files changed

+52
-6
lines changed

clidocstool_md.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +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
60+
}
61+
5662
log.Printf("INFO: Generating Markdown for %q", cmd.CommandPath())
5763
mdFile := mdFilename(cmd)
5864
sourcePath := filepath.Join(c.source, mdFile)
@@ -208,6 +214,9 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) {
208214
b.WriteString("### Subcommands\n\n")
209215
table := newMdTable("Name", "Description")
210216
for _, c := range cmd.Commands() {
217+
if c.Hidden {
218+
continue
219+
}
211220
table.AddRow(fmt.Sprintf("[`%s`](%s)", c.Name(), mdFilename(c)), c.Short)
212221
}
213222
b.WriteString(table.String() + "\n")

clidocstool_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ import (
2727
)
2828

2929
var (
30-
dockerCmd *cobra.Command
31-
buildxCmd *cobra.Command
32-
buildxBuildCmd *cobra.Command
33-
buildxStopCmd *cobra.Command
30+
dockerCmd *cobra.Command
31+
buildxCmd *cobra.Command
32+
buildxBuildCmd *cobra.Command
33+
buildxInstallCmd *cobra.Command
34+
buildxStopCmd *cobra.Command
3435
)
3536

3637
//nolint:errcheck
@@ -62,6 +63,13 @@ func init() {
6263
"aliases": "docker image build, docker buildx build, docker buildx b, docker build",
6364
},
6465
}
66+
buildxInstallCmd = &cobra.Command{
67+
Use: "install",
68+
Short: "Install buildx as a 'docker builder' alias",
69+
Args: cobra.ExactArgs(0),
70+
Run: func(cmd *cobra.Command, args []string) {},
71+
Hidden: true,
72+
}
6573
buildxStopCmd = &cobra.Command{
6674
Use: "stop [NAME]",
6775
Short: "Stop builder instance",
@@ -173,6 +181,7 @@ format: "default|<id>[=<socket>|<key>[,<key>]]"`)
173181
buildxBuildFlags.MarkHidden("force-rm")
174182

175183
buildxCmd.AddCommand(buildxBuildCmd)
184+
buildxCmd.AddCommand(buildxInstallCmd)
176185
buildxCmd.AddCommand(buildxStopCmd)
177186
dockerCmd.AddCommand(buildxCmd)
178187
}
@@ -192,7 +201,7 @@ func TestGenAllTree(t *testing.T) {
192201
require.NoError(t, err)
193202
require.NoError(t, c.GenAllTree())
194203

195-
for _, tt := range []string{"buildx.md", "buildx_build.md", "buildx_stop.md", "docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_stop.yaml"} {
204+
for _, tt := range []string{"buildx.md", "buildx_build.md", "buildx_stop.md", "docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_install.yaml", "docker_buildx_stop.yaml"} {
196205
tt := tt
197206
t.Run(tt, func(t *testing.T) {
198207
bres, err := os.ReadFile(filepath.Join(tmpdir, tt))

clidocstool_yaml.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type cmdDoc struct {
6262
InheritedOptions []cmdOption `yaml:"inherited_options,omitempty"`
6363
Example string `yaml:"examples,omitempty"`
6464
Deprecated bool
65+
Hidden bool
6566
MinAPIVersion string `yaml:"min_api_version,omitempty"`
6667
Experimental bool
6768
ExperimentalCLI bool
@@ -155,6 +156,7 @@ func (c *Client) genYamlCustom(cmd *cobra.Command, w io.Writer) error {
155156
Long: forceMultiLine(cmd.Long, longMaxWidth),
156157
Example: cmd.Example,
157158
Deprecated: len(cmd.Deprecated) > 0,
159+
Hidden: cmd.Hidden,
158160
}
159161

160162
if len(cliDoc.Long) == 0 {

clidocstool_yaml_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestGenYamlTree(t *testing.T) {
3636
require.NoError(t, err)
3737
require.NoError(t, c.GenYamlTree(buildxCmd))
3838

39-
for _, tt := range []string{"docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_stop.yaml"} {
39+
for _, tt := range []string{"docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_install.yaml", "docker_buildx_stop.yaml"} {
4040
tt := tt
4141
t.Run(tt, func(t *testing.T) {
4242
bres, err := os.ReadFile(filepath.Join(tmpdir, tt))

fixtures/docker_buildx.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ options:
2020
kubernetes: false
2121
swarm: false
2222
deprecated: false
23+
hidden: false
2324
experimental: false
2425
experimentalcli: false
2526
kubernetes: false

fixtures/docker_buildx_build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ inherited_options:
365365
kubernetes: false
366366
swarm: false
367367
deprecated: false
368+
hidden: false
368369
experimental: false
369370
experimentalcli: false
370371
kubernetes: false

fixtures/docker_buildx_install.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
command: docker buildx install
2+
short: Install buildx as a 'docker builder' alias
3+
long: Install buildx as a 'docker builder' alias
4+
usage: docker buildx install
5+
pname: docker buildx
6+
plink: docker_buildx.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+
deprecated: false
18+
hidden: true
19+
experimental: false
20+
experimentalcli: false
21+
kubernetes: false
22+
swarm: false
23+

fixtures/docker_buildx_stop.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ inherited_options:
1515
kubernetes: false
1616
swarm: false
1717
deprecated: false
18+
hidden: false
1819
experimental: false
1920
experimentalcli: false
2021
kubernetes: false

0 commit comments

Comments
 (0)