From fee66543c3cd93ee8fd60ef07d523f8e0684f431 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Mon, 12 Feb 2024 17:53:50 +0200 Subject: [PATCH] feat(tools): Add docs alias generation Signed-off-by: Cezar Craciunoiu --- tools/gendocs/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/gendocs/main.go b/tools/gendocs/main.go index 76bac5a49..8b0a52d39 100644 --- a/tools/gendocs/main.go +++ b/tools/gendocs/main.go @@ -83,6 +83,14 @@ func generateMarkdown(cmd *cobra.Command, dir string) error { return err } + if hasAliases(cmd) { + buf.WriteString("## Aliases\n\n") + buf.WriteString("The `" + name + "` command can also be run as:\n\n") + buf.WriteString("```\n") + buf.WriteString(strings.Join(cmd.Aliases, ", ") + "\n") + buf.WriteString("```\n\n") + } + if hasSeeAlso(cmd) { buf.WriteString("## See Also\n\n") if cmd.HasParent() { @@ -164,6 +172,10 @@ func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error { return nil } +func hasAliases(cmd *cobra.Command) bool { + return len(cmd.Aliases) > 0 +} + // Test to see if we have a reason to print See Also information in docs // Basically this is a test for a parent command or a subcommand which is // both not deprecated and not the autogenerated help command.