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

Doc:(issue_1593) Add flag category topic in docs (v2-maint) #1653

Merged
merged 1 commit into from Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/v2/examples/flags.md
Expand Up @@ -230,6 +230,57 @@ That flag can then be set with `--lang spanish` or `-l spanish`. Note that
giving two different forms of the same flag in the same command invocation is an
error.

#### Grouping

You can associate a category for each flag to group them together in the help output, e.g:

```go
package main

import (
"log"
"os"

"github.com/urfave/cli/v2"
)

func main() {
app = &cli.App{
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "silent",
Aliases: []string{"s"},
Usage: "no messages",
Category: "Miscellaneous:",
},
&cli.BoolFlag{
Name: "perl-regexp",
Aliases: []string{"P"},
Usage: "PATTERNS are Perl regular expressions",
Category: "Pattern selection:",
},
},
}

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
```

Will result in help output like:

```
GLOBAL OPTIONS:
Miscellaneous:

--silent, -s no messages (default: false)

Pattern selection:

--perl-regexp, -P PATTERNS are Perl regular expressions (default: false)
```

#### Ordering

Flags for the application and commands are shown in the order they are defined.
Expand Down