Skip to content

Commit

Permalink
Add documentation for flags with custom variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
calebstewart committed May 8, 2024
1 parent d5e0c06 commit d04c5d2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit d04c5d2

Please sign in to comment.