Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for flags with custom variable names #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions content/home/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,27 @@ rootCmd.Flags().StringVarP(&Region, "region", "r", "", "AWS region (required)")
rootCmd.MarkFlagRequired("region")
```

### Custom flag variable names

You can change the name of the variable displayed after a flag in the help output
by using a special backtick syntax in the flag usage. This works for non-boolean
flag types. By default, the variable name is an educated guess based on the flag
type.

```go
rootCmd.Flags().String("normalflag", "", "unchanged variable name")
rootCmd.Flags().String("fancyflag", "", "enter a `fancyvalue` for this flag")
```

This results in flag help output like:

```
Flags:
--fancyflag fancyvalue enter a fancyvalue for this flag
-h, --help help for test
--normalflag string unchanged variable name
```

## Positional and Custom Arguments

Validation of positional arguments can be specified using the `Args` field
Expand Down