Merge pull request #38 from crazy-max/missing-hidden

Take hidden attribute into account
This commit is contained in:
Sebastiaan van Stijn 2023-06-27 15:35:38 +02:00 коммит произвёл GitHub
Родитель ce91c05798 851d1b74e9
Коммит 5cb124c70a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 52 добавлений и 6 удалений

Просмотреть файл

@ -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")

Просмотреть файл

@ -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|<id>[=<socket>|<key>[,<key>]]"`)
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))

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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))

Просмотреть файл

@ -20,6 +20,7 @@ options:
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false

Просмотреть файл

@ -365,6 +365,7 @@ inherited_options:
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false

Просмотреть файл

@ -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

Просмотреть файл

@ -15,6 +15,7 @@ inherited_options:
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false