copy cleanup, remove feature not present in pr
@@ -644,14 +644,10 @@ func main() {
#### Required Flags
-You can make a flag required by setting the `Required` field to `true`. If an end-user
-fails to provide a required flag, they will be shown a default error message, or a
-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.
+You can make a flag required by setting the `Required` field to `true`. If a user
+does not provide a required flag, they will be shown an error message.
-For example this:
+Take for example this app that reqiures the `lang` flag:
```go
package main
@@ -673,34 +669,18 @@ func main() {
Value: "english",
Usage: "language for the greeting",
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 {
- name := "Nefertiti"
- if c.NArg() > 0 {
- name = c.Args().Get(0)
- }
+
var output string
if c.String("lang") == "spanish" {
- output = "Hola " + name
+ output = "Hola"
} else {
- output = "Hello " + name
- }
-
- if c.String("mood") == "excited" {
- output = strings.ToUpper(output)
+ output = "Hello"
}
+ fmt.Println(output)
return nil
}
@@ -712,13 +692,10 @@ func main() {
}
```
-Creates an app that requires both `lang` and `mood` flags. If an attempt
-to run the app is made without either, the end-user will see the following
-prompts:
+If the app is run without the `lang` flag, the user will see the following message
```
-Required flag "mood" not set
-There's a problem: "lang" is a required flag
+Required flag "lang" not set
```
#### Default Values for help output
