-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): add autogenerated flags reference
- Loading branch information
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/kong/kubernetes-ingress-controller/v2/internal/manager" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
// This program generates markdown documentation for the KIC executable's flags. | ||
// It skips deprecated and hidden flags. | ||
func main() { | ||
cfg := manager.Config{} | ||
flags := cfg.FlagSet() | ||
|
||
markdown := strings.Builder{} | ||
markdown.WriteString("---\ntitle: CLI Arguments\n---<!-- vale off -->\n\nVarious settings and configurations of the controller can be tweaked\nusing CLI flags.\n\n## Environment variables\n\nEach flag defined in the table below can also be configured using\nan environment variable. The name of the environment variable is `CONTROLLER_`\nstring followed by the name of flag in uppercase.\n\nFor example, `--ingress-class` can be configured using the following\nenvironment variable:\n\n```\nCONTROLLER_INGRESS_CLASS=kong-foobar\n```\n\nIt is recommended that all the configuration is done via environment variables\nand not CLI flags.\n\n") | ||
markdown.WriteString("## Flags\n") | ||
markdown.WriteString("| Flag | Type | Description | Default |\n") | ||
markdown.WriteString("| ---- | ---- | ----------- | ------- |\n") | ||
|
||
flags.VisitAll(func(flag *pflag.Flag) { | ||
// Skip deprecated flags. | ||
if flag.Deprecated != "" { | ||
return | ||
} | ||
|
||
name := fmt.Sprintf("`--%s`", flag.Name) | ||
typ := fmt.Sprintf("`%s`", flag.Value.Type()) | ||
|
||
description := flag.Usage | ||
// Make sure the first letter is capitalized. | ||
if first := description[0]; first >= 'a' && first <= 'z' { | ||
description = strings.ToUpper(string(first)) + description[1:] | ||
} | ||
// Make sure the last character is a period. | ||
if last := description[len(description)-1]; last != '.' { | ||
description += "." | ||
} | ||
|
||
defaultValue := "" | ||
if flag.DefValue != "" { | ||
defaultValue = fmt.Sprintf("`%s`", flag.DefValue) | ||
} | ||
|
||
markdown.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", name, typ, description, defaultValue)) | ||
}) | ||
|
||
markdown.WriteString("\n<!-- vale on -->\n") | ||
fmt.Println(markdown.String()) | ||
} |