diff --git a/clidocstool_md.go b/clidocstool_md.go index 73d05c8..1dee58c 100644 --- a/clidocstool_md.go +++ b/clidocstool_md.go @@ -53,6 +53,12 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error { return nil } + // Skip hidden command + if cmd.Hidden { + log.Printf("INFO: Skipping Markdown for %q (hidden command)", cmd.CommandPath()) + return nil + } + log.Printf("INFO: Generating Markdown for %q", cmd.CommandPath()) mdFile := mdFilename(cmd) sourcePath := filepath.Join(c.source, mdFile) @@ -208,6 +214,9 @@ func mdCmdOutput(cmd *cobra.Command, old string) (string, error) { b.WriteString("### Subcommands\n\n") table := newMdTable("Name", "Description") for _, c := range cmd.Commands() { + if c.Hidden { + continue + } table.AddRow(fmt.Sprintf("[`%s`](%s)", c.Name(), mdFilename(c)), c.Short) } b.WriteString(table.String() + "\n") diff --git a/clidocstool_test.go b/clidocstool_test.go index 141bdd6..7b640d8 100644 --- a/clidocstool_test.go +++ b/clidocstool_test.go @@ -27,10 +27,11 @@ import ( ) var ( - dockerCmd *cobra.Command - buildxCmd *cobra.Command - buildxBuildCmd *cobra.Command - buildxStopCmd *cobra.Command + dockerCmd *cobra.Command + buildxCmd *cobra.Command + buildxBuildCmd *cobra.Command + buildxInstallCmd *cobra.Command + buildxStopCmd *cobra.Command ) //nolint:errcheck @@ -62,6 +63,13 @@ func init() { "aliases": "docker image build, docker buildx build, docker buildx b, docker build", }, } + buildxInstallCmd = &cobra.Command{ + Use: "install", + Short: "Install buildx as a 'docker builder' alias", + Args: cobra.ExactArgs(0), + Run: func(cmd *cobra.Command, args []string) {}, + Hidden: true, + } buildxStopCmd = &cobra.Command{ Use: "stop [NAME]", Short: "Stop builder instance", @@ -173,6 +181,7 @@ format: "default|[=|[,]]"`) buildxBuildFlags.MarkHidden("force-rm") buildxCmd.AddCommand(buildxBuildCmd) + buildxCmd.AddCommand(buildxInstallCmd) buildxCmd.AddCommand(buildxStopCmd) dockerCmd.AddCommand(buildxCmd) } @@ -192,7 +201,7 @@ func TestGenAllTree(t *testing.T) { require.NoError(t, err) require.NoError(t, c.GenAllTree()) - for _, tt := range []string{"buildx.md", "buildx_build.md", "buildx_stop.md", "docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_stop.yaml"} { + 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"} { tt := tt t.Run(tt, func(t *testing.T) { bres, err := os.ReadFile(filepath.Join(tmpdir, tt)) diff --git a/clidocstool_yaml.go b/clidocstool_yaml.go index f6ae6b8..5235242 100644 --- a/clidocstool_yaml.go +++ b/clidocstool_yaml.go @@ -62,6 +62,7 @@ type cmdDoc struct { InheritedOptions []cmdOption `yaml:"inherited_options,omitempty"` Example string `yaml:"examples,omitempty"` Deprecated bool + Hidden bool MinAPIVersion string `yaml:"min_api_version,omitempty"` Experimental bool ExperimentalCLI bool @@ -155,6 +156,7 @@ func (c *Client) genYamlCustom(cmd *cobra.Command, w io.Writer) error { Long: forceMultiLine(cmd.Long, longMaxWidth), Example: cmd.Example, Deprecated: len(cmd.Deprecated) > 0, + Hidden: cmd.Hidden, } if len(cliDoc.Long) == 0 { diff --git a/clidocstool_yaml_test.go b/clidocstool_yaml_test.go index a5892c0..ed3f023 100644 --- a/clidocstool_yaml_test.go +++ b/clidocstool_yaml_test.go @@ -36,7 +36,7 @@ func TestGenYamlTree(t *testing.T) { require.NoError(t, err) require.NoError(t, c.GenYamlTree(buildxCmd)) - for _, tt := range []string{"docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_stop.yaml"} { + for _, tt := range []string{"docker_buildx.yaml", "docker_buildx_build.yaml", "docker_buildx_install.yaml", "docker_buildx_stop.yaml"} { tt := tt t.Run(tt, func(t *testing.T) { bres, err := os.ReadFile(filepath.Join(tmpdir, tt)) diff --git a/fixtures/docker_buildx.yaml b/fixtures/docker_buildx.yaml index 85353c0..c8b5cb5 100644 --- a/fixtures/docker_buildx.yaml +++ b/fixtures/docker_buildx.yaml @@ -20,6 +20,7 @@ options: kubernetes: false swarm: false deprecated: false +hidden: false experimental: false experimentalcli: false kubernetes: false diff --git a/fixtures/docker_buildx_build.yaml b/fixtures/docker_buildx_build.yaml index b522ff7..bc08c65 100644 --- a/fixtures/docker_buildx_build.yaml +++ b/fixtures/docker_buildx_build.yaml @@ -365,6 +365,7 @@ inherited_options: kubernetes: false swarm: false deprecated: false +hidden: false experimental: false experimentalcli: false kubernetes: false diff --git a/fixtures/docker_buildx_install.yaml b/fixtures/docker_buildx_install.yaml new file mode 100644 index 0000000..7a41735 --- /dev/null +++ b/fixtures/docker_buildx_install.yaml @@ -0,0 +1,23 @@ +command: docker buildx install +short: Install buildx as a 'docker builder' alias +long: Install buildx as a 'docker builder' alias +usage: docker buildx install +pname: docker buildx +plink: docker_buildx.yaml +inherited_options: + - option: builder + value_type: string + description: Override the configured builder instance + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false +deprecated: false +hidden: true +experimental: false +experimentalcli: false +kubernetes: false +swarm: false + diff --git a/fixtures/docker_buildx_stop.yaml b/fixtures/docker_buildx_stop.yaml index cb47654..d33e09d 100644 --- a/fixtures/docker_buildx_stop.yaml +++ b/fixtures/docker_buildx_stop.yaml @@ -15,6 +15,7 @@ inherited_options: kubernetes: false swarm: false deprecated: false +hidden: false experimental: false experimentalcli: false kubernetes: false