-
Notifications
You must be signed in to change notification settings - Fork 30
Generate CLI Documentation from Go code #294
base: main
Are you sure you want to change the base?
Conversation
|
||
return cmd | ||
} | ||
|
||
// Custom template for TOP to fix the namespace usage statement (default template shows parent usage). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 = "" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do 👍
Proposed changes
make generate
rule which autogenerates the documentation.go run -ldflags '-X main.genDocs=true' cmd/nginx-meshctl/main.go > /dev/null
to just generate the documentation.top.go
andupgrade.go
since they were printing out some flags redundantly.Checklist
Before creating a PR, run through this checklist and mark each as complete.