From 1047a3303cd43cbc40a9984ef4ff25d8c2cc6a10 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 5 Sep 2022 11:34:00 -0400 Subject: [PATCH] Add to docs --- docs/v2/examples/flags.md | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/v2/examples/flags.md b/docs/v2/examples/flags.md index 2a629f7..ed7dab2 100644 --- a/docs/v2/examples/flags.md +++ b/docs/v2/examples/flags.md @@ -101,6 +101,45 @@ func main() { See full list of flags at https://pkg.go.dev/github.com/urfave/cli/v2 +For bool flags you can specify the flag multiple times to get a count(e.g -v -v -v or -vvv) + + +```go +package main + +import ( + "fmt" + "log" + "os" + + "github.com/urfave/cli/v2" +) + +func main() { + var count int + + app := &cli.App{ + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "foo", + Usage: "foo greeting", + Count: &count, + }, + }, + Action: func(cCtx *cli.Context) error { + fmt.Println("Count %d", count) + return nil + }, + } + + if err := app.Run(os.Args); err != nil { + log.Fatal(err) + } +} +``` + #### Placeholder Values Sometimes it's useful to specify a flag's value within the usage string itself. @@ -550,6 +589,7 @@ Will result in help output like: #### Precedence The precedence for flag value sources is as follows (highest to lowest): +eikdcclkkujudfjnhknkgruvlncbgvuckugignuhturk 0. Command line flag value from user 0. Environment variable (if specified)