Merge commit '7563894' into v3-porting
This commit is contained in:
commit
d3a4181800
6
.github/ISSUE_TEMPLATE/v1-bug-report.md
vendored
6
.github/ISSUE_TEMPLATE/v1-bug-report.md
vendored
@ -15,7 +15,7 @@ _**( Put the version of urfave/cli that you are using here )**_
|
|||||||
|
|
||||||
- [ ] Are you running the latest v1 release? The list of releases is [here](https://github.com/urfave/cli/releases).
|
- [ ] Are you running the latest v1 release? The list of releases is [here](https://github.com/urfave/cli/releases).
|
||||||
- [ ] Did you check the manual for your release? The v1 manual is [here](https://github.com/urfave/cli/blob/main/docs/v1/manual.md).
|
- [ ] Did you check the manual for your release? The v1 manual is [here](https://github.com/urfave/cli/blob/main/docs/v1/manual.md).
|
||||||
- [ ] Did you perform a search about this problem? Here's the [Github guide](https://help.github.com/en/github/managing-your-work-on-github/using-search-to-filter-issues-and-pull-requests) about searching.
|
- [ ] Did you perform a search about this problem? Here's the [GitHub guide](https://help.github.com/en/github/managing-your-work-on-github/using-search-to-filter-issues-and-pull-requests) about searching.
|
||||||
|
|
||||||
## Dependency Management
|
## Dependency Management
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ reproduction steps above?
|
|||||||
|
|
||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|
||||||
If the issue relates to a specific open source Github repo, please
|
If the issue relates to a specific open source GitHub repo, please
|
||||||
link that repo here.
|
link that repo here.
|
||||||
|
|
||||||
If you can reproduce this issue with a public CI system, please
|
If you can reproduce this issue with a public CI system, please
|
||||||
@ -59,7 +59,7 @@ link a failing build here.
|
|||||||
## Want to fix this yourself?
|
## Want to fix this yourself?
|
||||||
|
|
||||||
We'd love to have more contributors on this project! If the fix for
|
We'd love to have more contributors on this project! If the fix for
|
||||||
this bug is easily explained and very small, free free to create a
|
this bug is easily explained and very small, feel free to create a
|
||||||
pull request for it. You'll want to base the PR off the `v1`
|
pull request for it. You'll want to base the PR off the `v1`
|
||||||
branch, all `v1` bug fix releases will be made from that branch.
|
branch, all `v1` bug fix releases will be made from that branch.
|
||||||
|
|
||||||
|
6
.github/ISSUE_TEMPLATE/v2-bug-report.md
vendored
6
.github/ISSUE_TEMPLATE/v2-bug-report.md
vendored
@ -15,7 +15,7 @@ _**( Put the version of urfave/cli that you are using here )**_
|
|||||||
|
|
||||||
- [ ] Are you running the latest v2 release? The list of releases is [here](https://github.com/urfave/cli/releases).
|
- [ ] Are you running the latest v2 release? The list of releases is [here](https://github.com/urfave/cli/releases).
|
||||||
- [ ] Did you check the manual for your release? The v2 manual is [here](https://github.com/urfave/cli/blob/main/docs/v2/manual.md)
|
- [ ] Did you check the manual for your release? The v2 manual is [here](https://github.com/urfave/cli/blob/main/docs/v2/manual.md)
|
||||||
- [ ] Did you perform a search about this problem? Here's the [Github guide](https://help.github.com/en/github/managing-your-work-on-github/using-search-to-filter-issues-and-pull-requests) about searching.
|
- [ ] Did you perform a search about this problem? Here's the [GitHub guide](https://help.github.com/en/github/managing-your-work-on-github/using-search-to-filter-issues-and-pull-requests) about searching.
|
||||||
|
|
||||||
## Dependency Management
|
## Dependency Management
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ reproduction steps above?
|
|||||||
|
|
||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|
||||||
If the issue relates to a specific open source Github repo, please
|
If the issue relates to a specific open source GitHub repo, please
|
||||||
link that repo here.
|
link that repo here.
|
||||||
|
|
||||||
If you can reproduce this issue with a public CI system, please
|
If you can reproduce this issue with a public CI system, please
|
||||||
@ -59,7 +59,7 @@ link a failing build here.
|
|||||||
## Want to fix this yourself?
|
## Want to fix this yourself?
|
||||||
|
|
||||||
We'd love to have more contributors on this project! If the fix for
|
We'd love to have more contributors on this project! If the fix for
|
||||||
this bug is easily explained and very small, free free to create a
|
this bug is easily explained and very small, feel free to create a
|
||||||
pull request for it.
|
pull request for it.
|
||||||
|
|
||||||
## Run `go version` and paste its output here
|
## Run `go version` and paste its output here
|
||||||
|
2
.github/ISSUE_TEMPLATE/v2-feature-request.md
vendored
2
.github/ISSUE_TEMPLATE/v2-feature-request.md
vendored
@ -11,7 +11,7 @@ assignees: ''
|
|||||||
|
|
||||||
* [ ] Are you running the latest v2 release? The list of releases is [here](https://github.com/urfave/cli/releases).
|
* [ ] Are you running the latest v2 release? The list of releases is [here](https://github.com/urfave/cli/releases).
|
||||||
* [ ] Did you check the manual for your release? The v2 manual is [here](https://github.com/urfave/cli/blob/main/docs/v2/manual.md).
|
* [ ] Did you check the manual for your release? The v2 manual is [here](https://github.com/urfave/cli/blob/main/docs/v2/manual.md).
|
||||||
* [ ] Did you perform a search about this feature? Here's the [Github guide](https://help.github.com/en/github/managing-your-work-on-github/using-search-to-filter-issues-and-pull-requests) about searching.
|
* [ ] Did you perform a search about this feature? Here's the [GitHub guide](https://help.github.com/en/github/managing-your-work-on-github/using-search-to-filter-issues-and-pull-requests) about searching.
|
||||||
|
|
||||||
## What problem does this solve?
|
## What problem does this solve?
|
||||||
|
|
||||||
|
@ -1454,7 +1454,7 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
expectedAnError: true,
|
expectedAnError: true,
|
||||||
},
|
},
|
||||||
// assertion: inputing --help, when a required flag is present, does not error
|
// assertion: inputting --help, when a required flag is present, does not error
|
||||||
{
|
{
|
||||||
testCase: "valid_case_help_input_with_required_flag_on_app",
|
testCase: "valid_case_help_input_with_required_flag_on_app",
|
||||||
appRunInput: []string{"myCLI", "--help"},
|
appRunInput: []string{"myCLI", "--help"},
|
||||||
@ -2581,7 +2581,7 @@ func TestWhenExitSubCommandWithCodeThenAppQuitUnexpectedly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if exitCodeFromExitErrHandler != testCode {
|
if exitCodeFromExitErrHandler != testCode {
|
||||||
t.Errorf("exitCodeFromOsExiter valeu should be %v, but its value is %v", testCode, exitCodeFromExitErrHandler)
|
t.Errorf("exitCodeFromOsExiter value should be %v, but its value is %v", testCode, exitCodeFromExitErrHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,12 +196,12 @@ View [unreleased 1.22.X] series changes.
|
|||||||
there are no `ExitCoder`s in the `MultiError`.
|
there are no `ExitCoder`s in the `MultiError`.
|
||||||
* Fixed YAML file loading on Windows (previously would fail validate the file path)
|
* Fixed YAML file loading on Windows (previously would fail validate the file path)
|
||||||
* Subcommand `Usage`, `Description`, `ArgsUsage`, `OnUsageError` correctly
|
* Subcommand `Usage`, `Description`, `ArgsUsage`, `OnUsageError` correctly
|
||||||
propogated
|
propagated
|
||||||
* `ErrWriter` is now passed downwards through command structure to avoid the
|
* `ErrWriter` is now passed downwards through command structure to avoid the
|
||||||
need to redefine it
|
need to redefine it
|
||||||
* Pass `Command` context into `OnUsageError` rather than parent context so that
|
* Pass `Command` context into `OnUsageError` rather than parent context so that
|
||||||
all fields are avaiable
|
all fields are available
|
||||||
* Errors occuring in `Before` funcs are no longer double printed
|
* Errors occurring in `Before` funcs are no longer double printed
|
||||||
* Use `UsageText` in the help templates for commands and subcommands if
|
* Use `UsageText` in the help templates for commands and subcommands if
|
||||||
defined; otherwise build the usage as before (was previously ignoring this
|
defined; otherwise build the usage as before (was previously ignoring this
|
||||||
field)
|
field)
|
||||||
@ -225,7 +225,7 @@ View [unreleased 1.22.X] series changes.
|
|||||||
`CustomAppHelpTemplate`
|
`CustomAppHelpTemplate`
|
||||||
* Support for arbitrary key/value fields on `App` to be used with
|
* Support for arbitrary key/value fields on `App` to be used with
|
||||||
`CustomAppHelpTemplate` via `ExtraInfo`
|
`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`
|
`cli.Flag`s allowing for the use of custom flags satisfying the `cli.Flag`
|
||||||
interface to be used.
|
interface to be used.
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ won't be able to call those. This reduces the resulting binary size by about
|
|||||||
### Supported platforms
|
### Supported platforms
|
||||||
|
|
||||||
cli is tested against multiple versions of Go on Linux, and against the latest
|
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
|
for builds. To see our currently supported go versions and platforms, look at
|
||||||
the [github workflow
|
the [github workflow
|
||||||
configuration](https://github.com/urfave/cli/blob/main/.github/workflows/cli.yml).
|
configuration](https://github.com/urfave/cli/blob/main/.github/workflows/cli.yml).
|
||||||
|
@ -596,3 +596,53 @@ The precedence for flag value sources is as follows (highest to lowest):
|
|||||||
0. Environment variable (if specified)
|
0. Environment variable (if specified)
|
||||||
0. Configuration file (if specified)
|
0. Configuration file (if specified)
|
||||||
0. Default defined on the flag
|
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": ["--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]
|
||||||
|
```
|
||||||
|
@ -98,7 +98,7 @@ func NewExitError(message interface{}, exitCode int) ExitCoder {
|
|||||||
//
|
//
|
||||||
// This is the simplest way to trigger a non-zero exit code for an App without
|
// This is the simplest way to trigger a non-zero exit code for an App without
|
||||||
// having to call os.Exit manually. During testing, this behavior can be avoided
|
// having to call os.Exit manually. During testing, this behavior can be avoided
|
||||||
// by overiding the ExitErrHandler function on an App or the package-global
|
// by overriding the ExitErrHandler function on an App or the package-global
|
||||||
// OsExiter function.
|
// OsExiter function.
|
||||||
func Exit(message interface{}, exitCode int) ExitCoder {
|
func Exit(message interface{}, exitCode int) ExitCoder {
|
||||||
return &exitError{
|
return &exitError{
|
||||||
|
2
fish.go
2
fish.go
@ -98,7 +98,7 @@ func (a *App) prepareFishCommands(commands []*Command, allCommands *[]string, pr
|
|||||||
a.prepareFishFlags(command.VisibleFlags(), command.Names())...,
|
a.prepareFishFlags(command.VisibleFlags(), command.Names())...,
|
||||||
)
|
)
|
||||||
|
|
||||||
// recursevly iterate subcommands
|
// recursively iterate subcommands
|
||||||
if len(command.Subcommands) > 0 {
|
if len(command.Subcommands) > 0 {
|
||||||
completions = append(
|
completions = append(
|
||||||
completions,
|
completions,
|
||||||
|
@ -840,7 +840,7 @@ func Exit(message interface{}, exitCode int) ExitCoder
|
|||||||
|
|
||||||
This is the simplest way to trigger a non-zero exit code for an App
|
This is the simplest way to trigger a non-zero exit code for an App
|
||||||
without having to call os.Exit manually. During testing, this behavior
|
without having to call os.Exit manually. During testing, this behavior
|
||||||
can be avoided by overiding the ExitErrHandler function on an App or the
|
can be avoided by overriding the ExitErrHandler function on an App or the
|
||||||
package-global OsExiter function.
|
package-global OsExiter function.
|
||||||
|
|
||||||
func NewExitError(message interface{}, exitCode int) ExitCoder
|
func NewExitError(message interface{}, exitCode int) ExitCoder
|
||||||
|
4
help.go
4
help.go
@ -60,7 +60,7 @@ var helpCommand = &Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Case 1 & 2
|
// Case 1 & 2
|
||||||
// Special case when running help on main app itself as opposed to indivdual
|
// Special case when running help on main app itself as opposed to individual
|
||||||
// commands/subcommands
|
// commands/subcommands
|
||||||
if cCtx.parentContext.App == nil {
|
if cCtx.parentContext.App == nil {
|
||||||
_ = ShowAppHelp(cCtx)
|
_ = ShowAppHelp(cCtx)
|
||||||
@ -188,7 +188,7 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) {
|
|||||||
// this will get total count utf8 letters in flag name
|
// this will get total count utf8 letters in flag name
|
||||||
count := utf8.RuneCountInString(name)
|
count := utf8.RuneCountInString(name)
|
||||||
if count > 2 {
|
if count > 2 {
|
||||||
count = 2 // resuse this count to generate single - or -- in flag completion
|
count = 2 // reuse this count to generate single - or -- in flag completion
|
||||||
}
|
}
|
||||||
// if flag name has more than one utf8 letter and last argument in cli has -- prefix then
|
// if flag name has more than one utf8 letter and last argument in cli has -- prefix then
|
||||||
// skip flag completion for short flags example -v or -x
|
// skip flag completion for short flags example -v or -x
|
||||||
|
@ -899,7 +899,7 @@ VERSION:
|
|||||||
|
|
||||||
func TestShowAppHelp_UsageText(t *testing.T) {
|
func TestShowAppHelp_UsageText(t *testing.T) {
|
||||||
app := &App{
|
app := &App{
|
||||||
UsageText: "This is a sinlge line of UsageText",
|
UsageText: "This is a single line of UsageText",
|
||||||
Commands: []*Command{
|
Commands: []*Command{
|
||||||
{
|
{
|
||||||
Name: "frobbly",
|
Name: "frobbly",
|
||||||
@ -912,7 +912,7 @@ func TestShowAppHelp_UsageText(t *testing.T) {
|
|||||||
|
|
||||||
_ = app.Run([]string{"foo"})
|
_ = app.Run([]string{"foo"})
|
||||||
|
|
||||||
if !strings.Contains(output.String(), "This is a sinlge line of UsageText") {
|
if !strings.Contains(output.String(), "This is a single line of UsageText") {
|
||||||
t.Errorf("expected output to include usage text; got: %q", output.String())
|
t.Errorf("expected output to include usage text; got: %q", output.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
testdata/godoc-v2.x.txt
vendored
2
testdata/godoc-v2.x.txt
vendored
@ -840,7 +840,7 @@ func Exit(message interface{}, exitCode int) ExitCoder
|
|||||||
|
|
||||||
This is the simplest way to trigger a non-zero exit code for an App
|
This is the simplest way to trigger a non-zero exit code for an App
|
||||||
without having to call os.Exit manually. During testing, this behavior
|
without having to call os.Exit manually. During testing, this behavior
|
||||||
can be avoided by overiding the ExitErrHandler function on an App or the
|
can be avoided by overriding the ExitErrHandler function on an App or the
|
||||||
package-global OsExiter function.
|
package-global OsExiter function.
|
||||||
|
|
||||||
func NewExitError(message interface{}, exitCode int) ExitCoder
|
func NewExitError(message interface{}, exitCode int) ExitCoder
|
||||||
|
Loading…
Reference in New Issue
Block a user