Skip to content
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

Take hidden attribute into account #38

Merged
merged 2 commits into from
Jun 27, 2023
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
9 changes: 9 additions & 0 deletions clidocstool_md.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't think we need to log here, we already print log above for the command being skipped.

}
table.AddRow(fmt.Sprintf("[`%s`](%s)", c.Name(), mdFilename(c)), c.Short)
}
b.WriteString(table.String() + "\n")
Expand Down
19 changes: 14 additions & 5 deletions clidocstool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -173,6 +181,7 @@ format: "default|<id>[=<socket>|<key>[,<key>]]"`)
buildxBuildFlags.MarkHidden("force-rm")

buildxCmd.AddCommand(buildxBuildCmd)
buildxCmd.AddCommand(buildxInstallCmd)
buildxCmd.AddCommand(buildxStopCmd)
dockerCmd.AddCommand(buildxCmd)
}
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions clidocstool_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion clidocstool_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions fixtures/docker_buildx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ options:
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
Expand Down
1 change: 1 addition & 0 deletions fixtures/docker_buildx_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ inherited_options:
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
Expand Down
23 changes: 23 additions & 0 deletions fixtures/docker_buildx_install.yaml
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions fixtures/docker_buildx_stop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ inherited_options:
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
Expand Down