From d04c5d225d1e54d0d825a32cafd5ed1a114f4584 Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Tue, 7 May 2024 21:58:11 -0400 Subject: [PATCH] Add documentation for flags with custom variable names --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 7eacc5bd..73b66d9d 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,22 @@ It is possible to mark a flag as hidden, meaning it will still function as norma flags.MarkHidden("secretFlag") ``` +## Custom flag variable names +It is possible to change the variable name used in command help output for non-boolean flags. By default, the variable name is an educated guess based on the flag type. + +**Example** +```go +flags.String("normalflag", "", "unchanged variable name") +flags.String("fancyflag", "", "enter a `fancyvalue` for this flag") +flags.PrintDefaults() +``` + +**Output** +``` + --fancyflag fancyvalue enter a fancyvalue for this flag + --normalflag string unchanged variable name +``` + ## Disable sorting of flags `pflag` allows you to disable sorting of flags for help and usage message.