Merge commit '7563894' into v3-porting

This commit is contained in:
2022-11-07 08:30:04 -05:00
13 changed files with 72 additions and 22 deletions

View File

@@ -196,12 +196,12 @@ View [unreleased 1.22.X] series changes.
there are no `ExitCoder`s in the `MultiError`.
* Fixed YAML file loading on Windows (previously would fail validate the file path)
* Subcommand `Usage`, `Description`, `ArgsUsage`, `OnUsageError` correctly
propogated
propagated
* `ErrWriter` is now passed downwards through command structure to avoid the
need to redefine it
* Pass `Command` context into `OnUsageError` rather than parent context so that
all fields are avaiable
* Errors occuring in `Before` funcs are no longer double printed
all fields are available
* Errors occurring in `Before` funcs are no longer double printed
* Use `UsageText` in the help templates for commands and subcommands if
defined; otherwise build the usage as before (was previously ignoring this
field)
@@ -225,7 +225,7 @@ View [unreleased 1.22.X] series changes.
`CustomAppHelpTemplate`
* Support for arbitrary key/value fields on `App` to be used with
`CustomAppHelpTemplate` via `ExtraInfo`
* `HelpFlag`, `VersionFlag`, and `BashCompletionFlag` changed to explictly be
* `HelpFlag`, `VersionFlag`, and `BashCompletionFlag` changed to explicitly be
`cli.Flag`s allowing for the use of custom flags satisfying the `cli.Flag`
interface to be used.

View File

@@ -67,7 +67,7 @@ won't be able to call those. This reduces the resulting binary size by about
### Supported platforms
cli is tested against multiple versions of Go on Linux, and against the latest
released version of Go on OS X and Windows. This project uses Github Actions
released version of Go on OS X and Windows. This project uses GitHub Actions
for builds. To see our currently supported go versions and platforms, look at
the [github workflow
configuration](https://github.com/urfave/cli/blob/main/.github/workflows/cli.yml).

View File

@@ -596,3 +596,53 @@ The precedence for flag value sources is as follows (highest to lowest):
0. Environment variable (if specified)
0. Configuration file (if specified)
0. Default defined on the flag
#### Flag Actions
Handlers can be registered per flag which are triggered after a flag has been processed.
This can be used for a variety of purposes, one of which is flag validation
<!-- {
"args": ["&#45;&#45;port","70000"],
"error": "Flag port value 70000 out of range[0-65535]"
} -->
```go
package main
import (
"log"
"os"
"fmt"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Flags: []cli.Flag{
&cli.IntFlag{
Name: "port",
Usage: "Use a randomized port",
Value: 0,
DefaultText: "random",
Action: func(ctx *cli.Context, v int) error {
if v >= 65536 {
return fmt.Errorf("Flag port value %v out of range[0-65535]", v)
}
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
```
Will result in help output like:
```
Flag port value 70000 out of range[0-65535]
```