Skip to content

skip hidden command recursively #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clidocstool_man.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 6 additions & 4 deletions clidocstool_md.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
34 changes: 27 additions & 7 deletions clidocstool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -223,6 +236,8 @@ format: "default|<id>[=<socket>|<key>[,<key>]]"`)

buildxCmd.AddCommand(buildxBuildCmd)
buildxCmd.AddCommand(buildxDialStdioCmd)
buildxImagetoolsCmd.AddCommand(buildxImagetoolsCreateCmd)
buildxCmd.AddCommand(buildxImagetoolsCmd)
buildxCmd.AddCommand(buildxInstallCmd)
buildxCmd.AddCommand(buildxStopCmd)
dockerCmd.AddCommand(buildxCmd)
Expand All @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions clidocstool_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +172 to +174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should keep these for the YAML docs (being more "data" then "end-result")?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The YAML file is still generated. What's changed is hidden attribute is now inherited from parent if set: https://github.com/docker/cli-docs-tool/pull/65/files#diff-cce07c459f10c3f29f937920cb8ba11cc3ab7028890917e036b3241da8940febR28

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! Sorry ignore me then 🤗

if v, ok := curr.Annotations["version"]; ok && cliDoc.MinAPIVersion == "" {
cliDoc.MinAPIVersion = v
}
Expand Down
22 changes: 0 additions & 22 deletions fixtures/docker-buildx-install.1

This file was deleted.

37 changes: 37 additions & 0 deletions fixtures/docker_buildx_imagetools.yaml
Original file line number Diff line number Diff line change
@@ -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

33 changes: 33 additions & 0 deletions fixtures/docker_buildx_imagetools_create.yaml
Original file line number Diff line number Diff line change
@@ -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