From 1b98d76caebbbe10d077118df8545be3b4d363f2 Mon Sep 17 00:00:00 2001 From: Phil Prasek Date: Wed, 30 Oct 2024 11:35:31 -0700 Subject: [PATCH] address feedback and add experimental option rendering Signed-off-by: Phil Prasek --- temporalcli/commandsgen/docs.go | 12 ++++++- temporalcli/commandsgen/parse.go | 56 -------------------------------- 2 files changed, 11 insertions(+), 57 deletions(-) diff --git a/temporalcli/commandsgen/docs.go b/temporalcli/commandsgen/docs.go index f71f7ac6..8742d7c6 100644 --- a/temporalcli/commandsgen/docs.go +++ b/temporalcli/commandsgen/docs.go @@ -81,7 +81,7 @@ func (w *docWriter) writeSubcommand(c *Command) { w.fileMap[fileName].WriteString(prefix + " " + c.LeafName + "\n\n") w.fileMap[fileName].WriteString(c.Description + "\n\n") - if c.IsLeafCommand { + if isLeafCommand(c) { w.fileMap[fileName].WriteString("Use the following options to change the behavior of this command.\n\n") // gather options from command and all options aviailable from parent commands @@ -101,6 +101,12 @@ func (w *docWriter) writeSubcommand(c *Command) { if len(option.Short) > 0 { w.fileMap[c.FileName].WriteString("Alias: `" + option.Short + "`\n\n") } + + if option.Experimental { + w.fileMap[fileName].WriteString(":::note" + "\n\n") + w.fileMap[fileName].WriteString("Option is experimental." + "\n\n") + w.fileMap[fileName].WriteString(":::" + "\n\n") + } } } } @@ -130,3 +136,7 @@ func encodeJSONExample(v string) string { v = re.ReplaceAllString(v, "`$1`") return v } + +func isLeafCommand(c *Command) bool { + return len(c.Children) == 0 +} diff --git a/temporalcli/commandsgen/parse.go b/temporalcli/commandsgen/parse.go index 93fcd5f4..96cea139 100644 --- a/temporalcli/commandsgen/parse.go +++ b/temporalcli/commandsgen/parse.go @@ -48,15 +48,11 @@ type ( OptionSets []string `yaml:"option-sets"` Docs Docs `yaml:"docs"` Index int - Base *Command Parent *Command Children []*Command Depth int FileName string - SubCommandName string - IsLeafCommand bool LeafName string - MaxChildDepth int } // Docs represents docs-only information that is not used in CLI generation. @@ -258,42 +254,6 @@ func enrichCommands(m Commands) (Commands, error) { } m.CommandList[c.Parent.Index].Children = append(m.CommandList[c.Parent.Index].Children, &m.CommandList[c.Index]) - - base := &c - for base.Depth > 1 { - base = base.Parent - } - m.CommandList[c.Index].Base = &m.CommandList[base.Index] - } - - setMaxChildDepthVisitor(*rootCommand, &m) - - for i, c := range m.CommandList { - if c.Parent == nil { - continue - } - - subCommandStartDepth := 1 - if c.Base.MaxChildDepth > 2 { - subCommandStartDepth = 2 - } - - subCommandName := "" - if c.Depth >= subCommandStartDepth { - subCommandName = strings.Join(strings.Split(c.FullName, " ")[subCommandStartDepth:], " ") - } - - if len(subCommandName) == 0 && c.Depth == 1 { - // for operator base command to show up in tags, keywords, etc. - subCommandName = c.LeafName - } - - m.CommandList[i].SubCommandName = subCommandName - - if len(c.Children) == 0 { - m.CommandList[i].IsLeafCommand = true - } - } // sorted ascending by full name of command (activity complete, batch list, etc) @@ -323,19 +283,3 @@ func sortChildrenVisitor(c *Command) { sortChildrenVisitor(command) } } - -func setMaxChildDepthVisitor(c Command, commands *Commands) int { - maxChildDepth := 0 - children := commands.CommandList[c.Index].Children - if len(children) > 0 { - for _, child := range children { - depth := setMaxChildDepthVisitor(*child, commands) - if depth > maxChildDepth { - maxChildDepth = depth - } - } - } - - commands.CommandList[c.Index].MaxChildDepth = maxChildDepth - return maxChildDepth + 1 -}