Skip to content

Commit

Permalink
Add to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Sep 6, 2022
1 parent 6bfa730 commit 1047a33
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/v2/examples/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- {
"output": "count 1"
} -->
```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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1047a33

Please sign in to comment.