Skip to content

Commit

Permalink
feat(tools): Add docs alias generation
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed Feb 12, 2024
1 parent a4c2ab8 commit fee6654
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/gendocs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fee6654

Please sign in to comment.