Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Generate CLI Documentation from Go code #294

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

keagarwal
Copy link
Contributor

Proposed changes

  • Added auto-generation for CLI documentation from Go code. A new command has been added to the make generate rule which autogenerates the documentation.
  • You can also run go run -ldflags '-X main.genDocs=true' cmd/nginx-meshctl/main.go > /dev/null to just generate the documentation.
  • Removed UsageTemplates from top.go and upgrade.go since they were printing out some flags redundantly.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@keagarwal keagarwal requested a review from a team as a code owner April 20, 2023 03:12

return cmd
}

// Custom template for TOP to fix the namespace usage statement (default template shows parent usage).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason top and upgrade had custom templates was because they have flags that override parent flags, and the default usage statements would show the parent usage for those flags, instead of the child usage of those flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I saw, the overriden flags were being printed out in the default usage statement, and not the parent usage. Adding the flag explicitly in the template was leading to the overriden flags being printed twice.


// generates a markdown file for each CLI command
_, b, _, _ := runtime.Caller(0)
docsPath := filepath.Join(filepath.Dir(b), "../../docs/content/reference")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have the CLI spit out all of this to stdout, and then the caller of the generator can pipe that output into our docs file. I don't want our CLI itself to write the file.

)

var (
pkgName = "nginx-meshctl"
version = "0.0.0"
commit = "local"
genDocs = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a variable built in, how about a flag that a user specifies, such as --verbose-usage or something along those lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants