Generate CLI reference also for sub-commands (#374)

* include all subcommands
Signed-off-by: Fabian Kammel <fk@edgeless.systems>
This commit is contained in:
Fabian Kammel 2022-08-17 16:58:36 +02:00 committed by GitHub
parent 059a3eacc0
commit 4176f038df
2 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,7 @@ on:
push: push:
branches: branches:
- main - main
workflow_dispatch:
jobs: jobs:
publish-to-docs: publish-to-docs:

View File

@ -21,7 +21,7 @@ func main() {
// Generate Markdown for all commands. // Generate Markdown for all commands.
cmdList := &bytes.Buffer{} cmdList := &bytes.Buffer{}
body := &bytes.Buffer{} body := &bytes.Buffer{}
for _, c := range rootCmd.Commands() { for _, c := range allSubCommands(rootCmd) {
name := c.Name() name := c.Name()
fmt.Fprintf(cmdList, "* [%v](#constellation-%v): %v\n", name, name, c.Short) fmt.Fprintf(cmdList, "* [%v](#constellation-%v): %v\n", name, name, c.Short)
if err := doc.GenMarkdown(c, body); err != nil { if err := doc.GenMarkdown(c, body); err != nil {
@ -34,3 +34,12 @@ func main() {
fmt.Printf("Commands:\n\n%s\n%s", cmdList, cleanedBody) fmt.Printf("Commands:\n\n%s\n%s", cmdList, cleanedBody)
} }
func allSubCommands(cmd *cobra.Command) []*cobra.Command {
var all []*cobra.Command
for _, c := range cmd.Commands() {
all = append(all, c)
all = append(all, allSubCommands(c)...)
}
return all
}