From bb7d7e4afda442854c7ab4d6cab0c15f6ac24366 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 19 May 2025 14:14:14 +0200 Subject: [PATCH] skip hidden command recursively Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- clidocstool_man.go | 8 ++++ clidocstool_md.go | 10 +++-- clidocstool_test.go | 34 +++++++++++++---- clidocstool_yaml.go | 3 ++ fixtures/docker-buildx-install.1 | 22 ----------- fixtures/docker_buildx_imagetools.yaml | 37 +++++++++++++++++++ fixtures/docker_buildx_imagetools_create.yaml | 33 +++++++++++++++++ 7 files changed, 114 insertions(+), 33 deletions(-) delete mode 100644 fixtures/docker-buildx-install.1 create mode 100644 fixtures/docker_buildx_imagetools.yaml create mode 100644 fixtures/docker_buildx_imagetools_create.yaml diff --git a/clidocstool_man.go b/clidocstool_man.go index e043f99..1b085f1 100644 --- a/clidocstool_man.go +++ b/clidocstool_man.go @@ -64,6 +64,14 @@ func (c *Client) genManTreeCustom(cmd *cobra.Command) error { return nil } + // Skip hidden command recursively + for curr := cmd; curr != nil; curr = curr.Parent() { + if curr.Hidden { + log.Printf("INFO: Skipping Man for %q (hidden command)", curr.CommandPath()) + return nil + } + } + log.Printf("INFO: Generating Man for %q", cmd.CommandPath()) return doc.GenManTreeFromOpts(cmd, doc.GenManTreeOptions{ diff --git a/clidocstool_md.go b/clidocstool_md.go index 46c2d09..4d52405 100644 --- a/clidocstool_md.go +++ b/clidocstool_md.go @@ -53,10 +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 + // Skip hidden command recursively + for curr := cmd; curr != nil; curr = curr.Parent() { + if curr.Hidden { + log.Printf("INFO: Skipping Markdown for %q (hidden command)", curr.CommandPath()) + return nil + } } log.Printf("INFO: Generating Markdown for %q", cmd.CommandPath()) diff --git a/clidocstool_test.go b/clidocstool_test.go index 0d3a488..12bd3a1 100644 --- a/clidocstool_test.go +++ b/clidocstool_test.go @@ -32,13 +32,15 @@ import ( ) var ( - dockerCmd *cobra.Command - attachCmd *cobra.Command - buildxCmd *cobra.Command - buildxBuildCmd *cobra.Command - buildxDialStdioCmd *cobra.Command - buildxInstallCmd *cobra.Command - buildxStopCmd *cobra.Command + dockerCmd *cobra.Command + attachCmd *cobra.Command + buildxCmd *cobra.Command + buildxBuildCmd *cobra.Command + buildxDialStdioCmd *cobra.Command + buildxImagetoolsCmd *cobra.Command + buildxImagetoolsCreateCmd *cobra.Command + buildxInstallCmd *cobra.Command + buildxStopCmd *cobra.Command ) //nolint:errcheck @@ -97,6 +99,17 @@ func setup() { Args: cobra.NoArgs, Run: func(*cobra.Command, []string) {}, } + buildxImagetoolsCmd = &cobra.Command{ + Use: "imagetools", + Short: "Commands to work on images in registry", + Run: func(*cobra.Command, []string) {}, + Hidden: true, + } + buildxImagetoolsCreateCmd = &cobra.Command{ + Use: "create [OPTIONS] [SOURCE...]", + Short: "Create a new image based on source images", + Run: func(*cobra.Command, []string) {}, + } buildxInstallCmd = &cobra.Command{ Use: "install", Short: "Install buildx as a 'docker builder' alias", @@ -223,6 +236,8 @@ format: "default|[=|[,]]"`) buildxCmd.AddCommand(buildxBuildCmd) buildxCmd.AddCommand(buildxDialStdioCmd) + buildxImagetoolsCmd.AddCommand(buildxImagetoolsCreateCmd) + buildxCmd.AddCommand(buildxImagetoolsCmd) buildxCmd.AddCommand(buildxInstallCmd) buildxCmd.AddCommand(buildxStopCmd) dockerCmd.AddCommand(buildxCmd) @@ -233,6 +248,11 @@ func TestGenAllTree(t *testing.T) { setup() tmpdir := t.TempDir() + // keep for testing + //tmpdir, err := os.MkdirTemp("", "cli-docs-tools") + //require.NoError(t, err) + //t.Log(tmpdir) + epoch, err := time.Parse("2006-Jan-02", "2020-Jan-10") require.NoError(t, err) t.Setenv("SOURCE_DATE_EPOCH", strconv.FormatInt(epoch.Unix(), 10)) diff --git a/clidocstool_yaml.go b/clidocstool_yaml.go index 2add1e6..c36afae 100644 --- a/clidocstool_yaml.go +++ b/clidocstool_yaml.go @@ -169,6 +169,9 @@ func (c *Client) genYamlCustom(cmd *cobra.Command, w io.Writer) error { // check recursively to handle inherited annotations for curr := cmd; curr != nil; curr = curr.Parent() { + if curr.Hidden { + cliDoc.Hidden = true + } if v, ok := curr.Annotations["version"]; ok && cliDoc.MinAPIVersion == "" { cliDoc.MinAPIVersion = v } diff --git a/fixtures/docker-buildx-install.1 b/fixtures/docker-buildx-install.1 deleted file mode 100644 index baf5595..0000000 --- a/fixtures/docker-buildx-install.1 +++ /dev/null @@ -1,22 +0,0 @@ -.nh -.TH "DOCKER" "1" "Jan 2020" "Docker Community" "Docker User Manuals" - -.SH NAME -docker-buildx-install - Install buildx as a 'docker builder' alias - - -.SH SYNOPSIS -\fBdocker buildx install\fP - - -.SH DESCRIPTION -Install buildx as a 'docker builder' alias - - -.SH OPTIONS INHERITED FROM PARENT COMMANDS -\fB--builder\fP="" - Override the configured builder instance - - -.SH SEE ALSO -\fBdocker-buildx(1)\fP diff --git a/fixtures/docker_buildx_imagetools.yaml b/fixtures/docker_buildx_imagetools.yaml new file mode 100644 index 0000000..ff58c4b --- /dev/null +++ b/fixtures/docker_buildx_imagetools.yaml @@ -0,0 +1,37 @@ +command: docker buildx imagetools +short: Commands to work on images in registry +long: Commands to work on images in registry +usage: docker buildx imagetools +pname: docker buildx +plink: docker_buildx.yaml +cname: + - docker buildx imagetools create +clink: + - docker_buildx_imagetools_create.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 + - option: help + value_type: bool + default_value: "false" + description: Print usage + deprecated: false + hidden: true + 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_imagetools_create.yaml b/fixtures/docker_buildx_imagetools_create.yaml new file mode 100644 index 0000000..146b299 --- /dev/null +++ b/fixtures/docker_buildx_imagetools_create.yaml @@ -0,0 +1,33 @@ +command: docker buildx imagetools create +short: Create a new image based on source images +long: Create a new image based on source images +usage: docker buildx imagetools create [OPTIONS] [SOURCE...] +pname: docker buildx imagetools +plink: docker_buildx_imagetools.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 + - option: help + value_type: bool + default_value: "false" + description: Print usage + deprecated: false + hidden: true + experimental: false + experimentalcli: false + kubernetes: false + swarm: false +deprecated: false +hidden: true +experimental: false +experimentalcli: false +kubernetes: false +swarm: false +