Merge branch 'master' into lynncyrin-patch-8
This commit is contained in:
commit
78a8ee98a9
9
.github/workflows/cli.yml
vendored
9
.github/workflows/cli.yml
vendored
@ -46,19 +46,20 @@ jobs:
|
|||||||
chmod +x $GOPATH/bin/gfmrun
|
chmod +x $GOPATH/bin/gfmrun
|
||||||
npm install markdown-toc
|
npm install markdown-toc
|
||||||
|
|
||||||
- name: Run Tests (v1)
|
- name: Run Tests
|
||||||
if: contains(github.base_ref, 'v1')
|
|
||||||
run: |
|
run: |
|
||||||
go run build.go vet
|
go run build.go vet
|
||||||
go run build.go test
|
go run build.go test
|
||||||
|
|
||||||
|
- name: Run Tests (v1)
|
||||||
|
if: contains(github.base_ref, 'v1')
|
||||||
|
run: |
|
||||||
go run build.go gfmrun docs/v1/manual.md
|
go run build.go gfmrun docs/v1/manual.md
|
||||||
go run build.go toc docs/v1/manual.md
|
go run build.go toc docs/v1/manual.md
|
||||||
|
|
||||||
- name: Run Tests (v2)
|
- name: Run Tests (v2)
|
||||||
if: contains(github.base_ref, 'master')
|
if: contains(github.base_ref, 'master')
|
||||||
run: |
|
run: |
|
||||||
go run build.go vet
|
|
||||||
go run build.go test
|
|
||||||
go run build.go gfmrun docs/v2/manual.md
|
go run build.go gfmrun docs/v2/manual.md
|
||||||
go run build.go toc docs/v2/manual.md
|
go run build.go toc docs/v2/manual.md
|
||||||
|
|
||||||
|
14
README.md
14
README.md
@ -1,7 +1,6 @@
|
|||||||
cli
|
cli
|
||||||
===
|
===
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/urfave/cli.svg?branch=master)](https://travis-ci.org/urfave/cli)
|
|
||||||
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/rtgk5xufi932pb2v?svg=true)](https://ci.appveyor.com/project/urfave/cli)
|
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/rtgk5xufi932pb2v?svg=true)](https://ci.appveyor.com/project/urfave/cli)
|
||||||
|
|
||||||
[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://godoc.org/github.com/urfave/cli)
|
[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://godoc.org/github.com/urfave/cli)
|
||||||
@ -20,6 +19,12 @@ Usage documentation exists for each major version. Don't know what version you'r
|
|||||||
- `v2` - [./docs/v2/manual.md](./docs/v2/manual.md)
|
- `v2` - [./docs/v2/manual.md](./docs/v2/manual.md)
|
||||||
- `v1` - [./docs/v1/manual.md](./docs/v1/manual.md)
|
- `v1` - [./docs/v1/manual.md](./docs/v1/manual.md)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Make sure you have a working Go environment. Go version 1.11+ is supported. [See the install instructions for Go](http://golang.org/doc/install.html).
|
||||||
|
|
||||||
|
Go Modules are strongly recommended when using this package. [See the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules).
|
||||||
|
|
||||||
### Using `v2` releases
|
### Using `v2` releases
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -37,7 +42,7 @@ import (
|
|||||||
### Using `v1` releases
|
### Using `v1` releases
|
||||||
|
|
||||||
```
|
```
|
||||||
$ go get github.com/urfave/cli
|
$ GO111MODULE=on go get github.com/urfave/cli
|
||||||
```
|
```
|
||||||
|
|
||||||
```go
|
```go
|
||||||
@ -48,11 +53,6 @@ import (
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
Make sure you have a working Go environment. Go version 1.10+ is supported. [See
|
|
||||||
the install instructions for Go](http://golang.org/doc/install.html).
|
|
||||||
|
|
||||||
### GOPATH
|
### GOPATH
|
||||||
|
|
||||||
Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can
|
Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can
|
||||||
|
@ -28,6 +28,9 @@ func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context {
|
|||||||
if parentCtx != nil {
|
if parentCtx != nil {
|
||||||
c.Context = parentCtx.Context
|
c.Context = parentCtx.Context
|
||||||
c.shellComplete = parentCtx.shellComplete
|
c.shellComplete = parentCtx.shellComplete
|
||||||
|
if parentCtx.flagSet == nil {
|
||||||
|
parentCtx.flagSet = &flag.FlagSet{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Command = &Command{}
|
c.Command = &Command{}
|
||||||
|
@ -344,6 +344,81 @@ func TestContextPropagation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextAttributeAccessing(t *testing.T) {
|
||||||
|
tdata := []struct {
|
||||||
|
testCase string
|
||||||
|
setBoolInput string
|
||||||
|
ctxBoolInput string
|
||||||
|
newContextInput *Context
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "empty",
|
||||||
|
setBoolInput: "",
|
||||||
|
ctxBoolInput: "",
|
||||||
|
newContextInput: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "empty_with_background_context",
|
||||||
|
setBoolInput: "",
|
||||||
|
ctxBoolInput: "",
|
||||||
|
newContextInput: &Context{Context: context.Background()},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "empty_set_bool_and_present_ctx_bool",
|
||||||
|
setBoolInput: "",
|
||||||
|
ctxBoolInput: "ctx-bool",
|
||||||
|
newContextInput: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "present_set_bool_and_present_ctx_bool_with_background_context",
|
||||||
|
setBoolInput: "",
|
||||||
|
ctxBoolInput: "ctx-bool",
|
||||||
|
newContextInput: &Context{Context: context.Background()},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "present_set_bool_and_present_ctx_bool",
|
||||||
|
setBoolInput: "ctx-bool",
|
||||||
|
ctxBoolInput: "ctx-bool",
|
||||||
|
newContextInput: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "present_set_bool_and_present_ctx_bool_with_background_context",
|
||||||
|
setBoolInput: "ctx-bool",
|
||||||
|
ctxBoolInput: "ctx-bool",
|
||||||
|
newContextInput: &Context{Context: context.Background()},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "present_set_bool_and_different_ctx_bool",
|
||||||
|
setBoolInput: "ctx-bool",
|
||||||
|
ctxBoolInput: "not-ctx-bool",
|
||||||
|
newContextInput: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "present_set_bool_and_different_ctx_bool_with_background_context",
|
||||||
|
setBoolInput: "ctx-bool",
|
||||||
|
ctxBoolInput: "not-ctx-bool",
|
||||||
|
newContextInput: &Context{Context: context.Background()},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tdata {
|
||||||
|
t.Run(test.testCase, func(t *testing.T) {
|
||||||
|
// setup
|
||||||
|
set := flag.NewFlagSet("some-flag-set-name", 0)
|
||||||
|
set.Bool(test.setBoolInput, false, "usage documentation")
|
||||||
|
ctx := NewContext(nil, set, test.newContextInput)
|
||||||
|
|
||||||
|
// logic under test
|
||||||
|
value := ctx.Bool(test.ctxBoolInput)
|
||||||
|
|
||||||
|
// assertions
|
||||||
|
if value != false {
|
||||||
|
t.Errorf("expected \"value\" to be false, but it was not")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCheckRequiredFlags(t *testing.T) {
|
func TestCheckRequiredFlags(t *testing.T) {
|
||||||
tdata := []struct {
|
tdata := []struct {
|
||||||
testCase string
|
testCase string
|
||||||
|
@ -6,6 +6,33 @@
|
|||||||
|
|
||||||
View [unreleased 2.X] series changes.
|
View [unreleased 2.X] series changes.
|
||||||
|
|
||||||
|
## [2.1.1] - 2019-12-24
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed a `Context` regression introduced in `v2.1.0` in [urfave/cli/pull/1014](https://github.com/urfave/cli/pull/1014) via [@lynncyrin](https://github.com/lynncyrin)
|
||||||
|
|
||||||
|
## [2.1.0] - 2019-12-24
|
||||||
|
|
||||||
|
These release notes were written for the git hash [ae84df4cef4a2a6f1a0cb1d41ea0f3af8755e5a8](https://github.com/urfave/cli/tree/ae84df4cef4a2a6f1a0cb1d41ea0f3af8755e5a8)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed some golint errors in [urfave/cli/pull/988](https://github.com/urfave/cli/pull/988) via [@liamchampton](https://github.com/liamchampton)
|
||||||
|
* Fixed a panic with flag completion [urfave/cli/pull/946](https://github.com/urfave/cli/pull/946) via [@unRob](https://github.com/unRob)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Changed docs generation to use visible flags in [urfave/cli/pull/999](https://github.com/urfave/cli/pull/999) via [@subpop](https://github.com/subpop)
|
||||||
|
* Changed `App.Run` to use an optional context for timeouts and cancellation in [urfave/cli/pull/975](https://github.com/urfave/cli/pull/975) via [@marwan-at-work](https://github.com/marwan-at-work)
|
||||||
|
* Changed version info to be hidden if the user has not defined a version in [urfave/cli/pull/955](https://github.com/urfave/cli/pull/955) via [@asahasrabuddhe](https://github.com/asahasrabuddhe)
|
||||||
|
* Changed docs generation to take into account multiple authors in [urfave/cli/pull/900](https://github.com/urfave/cli/pull/900) via [@saschagrunert](https://github.com/saschagrunert)
|
||||||
|
* Changed context to expose a `Value` accessor in [urfave/cli/pull/741](https://github.com/urfave/cli/pull/741) via [@corruptmemory](https://github.com/corruptmemory)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Added timestamp flag in [urfave/cli/pull/987](https://github.com/urfave/cli/pull/987) via [@drov0](https://github.com/drov0)
|
||||||
|
|
||||||
## [2.0.0] - 2019-11-17
|
## [2.0.0] - 2019-11-17
|
||||||
|
|
||||||
The V2 changes were all shipped in [urfave/cli/pull/892](https://github.com/urfave/cli/pull/892), which was created with the effort of over a dozen participants! They are:
|
The V2 changes were all shipped in [urfave/cli/pull/892](https://github.com/urfave/cli/pull/892), which was created with the effort of over a dozen participants! They are:
|
||||||
@ -520,7 +547,9 @@ signature of `func(*cli.Context) error`, as defined by `cli.ActionFunc`.
|
|||||||
### Added
|
### Added
|
||||||
- Initial implementation.
|
- Initial implementation.
|
||||||
|
|
||||||
[unreleased 2.X]: https://github.com/urfave/cli/compare/v2.0.0...HEAD
|
[unreleased 2.X]: https://github.com/urfave/cli/compare/v2.1.1...HEAD
|
||||||
|
[2.1.1]: https://github.com/urfave/cli/compare/v2.1.0...v2.1.1
|
||||||
|
[2.1.0]: https://github.com/urfave/cli/compare/v2.0.0...v2.1.0
|
||||||
[2.0.0]: https://github.com/urfave/cli/compare/v1.22.2...v2.0.0
|
[2.0.0]: https://github.com/urfave/cli/compare/v1.22.2...v2.0.0
|
||||||
|
|
||||||
[unreleased 1.22.X]: https://github.com/urfave/cli/compare/v1.22.2...v1
|
[unreleased 1.22.X]: https://github.com/urfave/cli/compare/v1.22.2...v1
|
||||||
|
@ -1460,13 +1460,15 @@ func main() {
|
|||||||
cli.ShowVersion(c)
|
cli.ShowVersion(c)
|
||||||
|
|
||||||
fmt.Printf("%#v\n", c.App.Command("doo"))
|
fmt.Printf("%#v\n", c.App.Command("doo"))
|
||||||
if c.Bool("infinite") {
|
// // uncomment when https://github.com/urfave/cli/pull/1014 is released
|
||||||
c.App.Run([]string{"app", "doo", "wop"})
|
// if c.Bool("infinite") {
|
||||||
}
|
// c.App.Run([]string{"app", "doo", "wop"})
|
||||||
|
// }
|
||||||
|
|
||||||
if c.Bool("forevar") {
|
// // uncomment when https://github.com/urfave/cli/pull/1014 is released
|
||||||
c.App.RunAsSubcommand(c)
|
// if c.Bool("forevar") {
|
||||||
}
|
// c.App.RunAsSubcommand(c)
|
||||||
|
// }
|
||||||
c.App.Setup()
|
c.App.Setup()
|
||||||
fmt.Printf("%#v\n", c.App.VisibleCategories())
|
fmt.Printf("%#v\n", c.App.VisibleCategories())
|
||||||
fmt.Printf("%#v\n", c.App.VisibleCommands())
|
fmt.Printf("%#v\n", c.App.VisibleCommands())
|
||||||
@ -1482,28 +1484,29 @@ func main() {
|
|||||||
set := flag.NewFlagSet("contrive", 0)
|
set := flag.NewFlagSet("contrive", 0)
|
||||||
nc := cli.NewContext(c.App, set, c)
|
nc := cli.NewContext(c.App, set, c)
|
||||||
|
|
||||||
fmt.Printf("%#v\n", nc.Args())
|
// // uncomment when https://github.com/urfave/cli/pull/1014 is released
|
||||||
fmt.Printf("%#v\n", nc.Bool("nope"))
|
// fmt.Printf("%#v\n", nc.Args())
|
||||||
fmt.Printf("%#v\n", !nc.Bool("nerp"))
|
// fmt.Printf("%#v\n", nc.Bool("nope"))
|
||||||
fmt.Printf("%#v\n", nc.Duration("howlong"))
|
// fmt.Printf("%#v\n", !nc.Bool("nerp"))
|
||||||
fmt.Printf("%#v\n", nc.Float64("hay"))
|
// fmt.Printf("%#v\n", nc.Duration("howlong"))
|
||||||
fmt.Printf("%#v\n", nc.Generic("bloop"))
|
// fmt.Printf("%#v\n", nc.Float64("hay"))
|
||||||
fmt.Printf("%#v\n", nc.Int64("bonk"))
|
// fmt.Printf("%#v\n", nc.Generic("bloop"))
|
||||||
fmt.Printf("%#v\n", nc.Int64Slice("burnks"))
|
// fmt.Printf("%#v\n", nc.Int64("bonk"))
|
||||||
fmt.Printf("%#v\n", nc.Int("bips"))
|
// fmt.Printf("%#v\n", nc.Int64Slice("burnks"))
|
||||||
fmt.Printf("%#v\n", nc.IntSlice("blups"))
|
// fmt.Printf("%#v\n", nc.Int("bips"))
|
||||||
fmt.Printf("%#v\n", nc.String("snurt"))
|
// fmt.Printf("%#v\n", nc.IntSlice("blups"))
|
||||||
fmt.Printf("%#v\n", nc.StringSlice("snurkles"))
|
// fmt.Printf("%#v\n", nc.String("snurt"))
|
||||||
fmt.Printf("%#v\n", nc.Uint("flub"))
|
// fmt.Printf("%#v\n", nc.StringSlice("snurkles"))
|
||||||
fmt.Printf("%#v\n", nc.Uint64("florb"))
|
// fmt.Printf("%#v\n", nc.Uint("flub"))
|
||||||
|
// fmt.Printf("%#v\n", nc.Uint64("florb"))
|
||||||
fmt.Printf("%#v\n", nc.FlagNames())
|
|
||||||
fmt.Printf("%#v\n", nc.IsSet("wat"))
|
|
||||||
fmt.Printf("%#v\n", nc.Set("wat", "nope"))
|
|
||||||
fmt.Printf("%#v\n", nc.NArg())
|
|
||||||
fmt.Printf("%#v\n", nc.NumFlags())
|
|
||||||
fmt.Printf("%#v\n", nc.Lineage()[1])
|
|
||||||
|
|
||||||
|
// // uncomment when https://github.com/urfave/cli/pull/1014 is released
|
||||||
|
// fmt.Printf("%#v\n", nc.FlagNames())
|
||||||
|
// fmt.Printf("%#v\n", nc.IsSet("wat"))
|
||||||
|
// fmt.Printf("%#v\n", nc.Set("wat", "nope"))
|
||||||
|
// fmt.Printf("%#v\n", nc.NArg())
|
||||||
|
// fmt.Printf("%#v\n", nc.NumFlags())
|
||||||
|
// fmt.Printf("%#v\n", nc.Lineage()[1])
|
||||||
nc.Set("wat", "also-nope")
|
nc.Set("wat", "also-nope")
|
||||||
|
|
||||||
ec := cli.Exit("ohwell", 86)
|
ec := cli.Exit("ohwell", 86)
|
||||||
|
Loading…
Reference in New Issue
Block a user