From b86f5135f67b9f7385f03fd7c19666f5d2168239 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Jul 2021 14:12:11 +0200 Subject: [PATCH] docs/yaml: add TODO for conditionally skipping root command Signed-off-by: Sebastiaan van Stijn --- docs/yaml/yaml.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/yaml/yaml.go b/docs/yaml/yaml.go index e5e875940f..9fb3871917 100644 --- a/docs/yaml/yaml.go +++ b/docs/yaml/yaml.go @@ -73,9 +73,23 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string return err } } - if !cmd.HasParent() { - return nil - } + + // TODO: conditionally skip the root command (for plugins) + // + // The "root" command used in the generator is just a "stub", and only has a + // list of subcommands, but not (e.g.) global options/flags. We should fix + // that, so that the YAML file for the docker "root" command contains the + // global flags. + // + // If we're using this code to generate YAML docs for a plugin, the root- + // command is even less useful; in that case, the root command represents + // the "docker" command, and is a "dummy" with no flags, and only a single + // subcommand (the plugin's top command). For plugins, we should skip the + // root command altogether, to prevent generating a useless YAML file. + // if !cmd.HasParent() { + // return nil + // } + basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".yaml" filename := filepath.Join(dir, basename) f, err := os.Create(filename)