Skip to content
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