diff --git a/docs/yaml/yaml.go b/docs/yaml/yaml.go index 10e2f61c6b..2dbe406bdb 100644 --- a/docs/yaml/yaml.go +++ b/docs/yaml/yaml.go @@ -39,6 +39,9 @@ type cmdDoc struct { Options []cmdOption `yaml:",omitempty"` InheritedOptions []cmdOption `yaml:"inherited_options,omitempty"` Example string `yaml:"examples,omitempty"` + Deprecated bool + MinAPIVersion string `yaml:"min_api_version,omitempty"` + Experimental bool } // GenYamlTree creates yaml structured ref files @@ -77,12 +80,11 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandle } // GenYamlCustom creates custom yaml output +// nolint: gocyclo func GenYamlCustom(cmd *cobra.Command, w io.Writer) error { cliDoc := cmdDoc{} cliDoc.Name = cmd.CommandPath() - // Check experimental: ok := cmd.Tags["experimental"] - cliDoc.Aliases = strings.Join(cmd.Aliases, ", ") cliDoc.Short = cmd.Short cliDoc.Long = cmd.Long @@ -97,6 +99,18 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer) error { if len(cmd.Example) > 0 { cliDoc.Example = cmd.Example } + if len(cmd.Deprecated) > 0 { + cliDoc.Deprecated = true + } + // Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack` + for curr := cmd; curr != nil; curr = curr.Parent() { + if v, ok := curr.Tags["version"]; ok && cliDoc.MinAPIVersion == "" { + cliDoc.MinAPIVersion = v + } + if _, ok := curr.Tags["experimental"]; ok && !cliDoc.Experimental { + cliDoc.Experimental = true + } + } flags := cmd.NonInheritedFlags() if flags.HasFlags() {