copy cleanup, remove feature not present in pr
This commit is contained in:
parent
e373baeb40
commit
daa24f660a
@ -644,14 +644,10 @@ func main() {
|
|||||||
|
|
||||||
#### Required Flags
|
#### Required Flags
|
||||||
|
|
||||||
You can make a flag required by setting the `Required` field to `true`. If an end-user
|
You can make a flag required by setting the `Required` field to `true`. If a user
|
||||||
fails to provide a required flag, they will be shown a default error message, or a
|
does not provide a required flag, they will be shown an error message.
|
||||||
custom message if one is defined. To define a custom error message for a required flag,
|
|
||||||
set the `RequiredFlagErr` field equal to a `cli.FlagErr` struct with a `Custom` field of `true`
|
|
||||||
and a `Message` field containing the custom error message. Default and custom error messages
|
|
||||||
can be mixed with default messages displayed before custom messages.
|
|
||||||
|
|
||||||
For example this:
|
Take for example this app that reqiures the `lang` flag:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@ -673,34 +669,18 @@ func main() {
|
|||||||
Value: "english",
|
Value: "english",
|
||||||
Usage: "language for the greeting",
|
Usage: "language for the greeting",
|
||||||
Required: true,
|
Required: true,
|
||||||
RequiredFlagErr: cli.FlagErr{
|
|
||||||
Custom: true,
|
|
||||||
Message: `There's a problem: "lang" is a required flag` ,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "mood",
|
|
||||||
Value: "normal",
|
|
||||||
Usage: "emphasis for the greeting",
|
|
||||||
Required: true,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Action = func(c *cli.Context) error {
|
app.Action = func(c *cli.Context) error {
|
||||||
name := "Nefertiti"
|
|
||||||
if c.NArg() > 0 {
|
|
||||||
name = c.Args().Get(0)
|
|
||||||
}
|
|
||||||
var output string
|
var output string
|
||||||
if c.String("lang") == "spanish" {
|
if c.String("lang") == "spanish" {
|
||||||
output = "Hola " + name
|
output = "Hola"
|
||||||
} else {
|
} else {
|
||||||
output = "Hello " + name
|
output = "Hello"
|
||||||
}
|
|
||||||
|
|
||||||
if c.String("mood") == "excited" {
|
|
||||||
output = strings.ToUpper(output)
|
|
||||||
}
|
}
|
||||||
|
fmt.Println(output)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -712,13 +692,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates an app that requires both `lang` and `mood` flags. If an attempt
|
If the app is run without the `lang` flag, the user will see the following message
|
||||||
to run the app is made without either, the end-user will see the following
|
|
||||||
prompts:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
Required flag "mood" not set
|
Required flag "lang" not set
|
||||||
There's a problem: "lang" is a required flag
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Default Values for help output
|
#### Default Values for help output
|
||||||
|
Loading…
Reference in New Issue
Block a user