Skip to content

Commit

Permalink
revert docs/v2/manual.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vipally committed Feb 8, 2021
1 parent ef9430e commit 06f6815
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
46 changes: 0 additions & 46 deletions docs/v2/manual.md
Expand Up @@ -14,7 +14,6 @@ cli v2 manual
+ [Values from the Environment](#values-from-the-environment)
+ [Values from files](#values-from-files)
+ [Values from alternate input sources (YAML, TOML, and others)](#values-from-alternate-input-sources-yaml-toml-and-others)
+ [Muti values](#multi-values)
+ [Required Flags](#required-flags)
+ [Default Values for help output](#default-values-for-help-output)
+ [Precedence](#precedence)
Expand Down Expand Up @@ -661,51 +660,6 @@ func main() {
}
```

#### Multi values

Slice flags(Float64SliceFlag, Int64SliceFlag, IntSliceFlag, StringSliceFlag) are designed to accept multi values.

Here is a sample of setting multi values for slice flags:

<!-- {
"output": "0-float64Sclice cli.Float64Slice{slice:[]float64{13.3, 14.4, 15.5, 16.6}, hasBeenSet:true}\n1-int64Sclice cli.Int64Slice{slice:[]int64{13, 14, 15, 16}, hasBeenSet:true}\n2-intSclice cli.IntSlice{slice:[]int{13, 14, 15, 16}, hasBeenSet:true}\n3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, hasBeenSet:true}",
} -->
```
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
func main() {
os.Args = []string{"multi_values",
"--stringSclice", "parsed1,parsed2", "--stringSclice", "parsed3,parsed4",
"--float64Sclice", "13.3,14.4", "--float64Sclice", "15.5,16.6",
"--int64Sclice", "13,14", "--int64Sclice", "15,16",
"--intSclice", "13,14", "--intSclice", "15,16",
}
app := cli.NewApp()
app.Name = "multi_values"
app.Flags = []cli.Flag{
&cli.StringSliceFlag{Name: "stringSclice"},
&cli.Float64SliceFlag{Name: "float64Sclice"},
&cli.Int64SliceFlag{Name: "int64Sclice"},
&cli.IntSliceFlag{Name: "intSclice"},
}
app.Action = func(ctx *cli.Context) error {
for i, v := range ctx.FlagNames() {
fmt.Printf("%d-%s %#v\n", i, v, ctx.Value(v))
}
return ctx.Err()
}
_ = app.Run(os.Args)
}
```

#### Required Flags

You can make a flag required by setting the `Required` field to `true`. If a user
Expand Down
2 changes: 1 addition & 1 deletion flag_float64_slice.go
Expand Up @@ -125,7 +125,7 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error {
if val != "" {
f.Value = &Float64Slice{}

for _, s := range strings.Split(val, ",") {
for _, s := range flagSplitMultiValues(val) {
if err := f.Value.Set(strings.TrimSpace(s)); err != nil {
return fmt.Errorf("could not parse %q as float64 slice value for flag %s: %s", f.Value, f.Name, err)
}
Expand Down

0 comments on commit 06f6815

Please sign in to comment.