Merge branch 'master' into lynncyrin-patch-6
This commit is contained in:
commit
fe731866a5
@ -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,12 @@
|
|||||||
|
|
||||||
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
|
## [2.1.0] - 2019-12-24
|
||||||
|
|
||||||
These release notes were written for the git hash [ae84df4cef4a2a6f1a0cb1d41ea0f3af8755e5a8](https://github.com/urfave/cli/tree/ae84df4cef4a2a6f1a0cb1d41ea0f3af8755e5a8)
|
These release notes were written for the git hash [ae84df4cef4a2a6f1a0cb1d41ea0f3af8755e5a8](https://github.com/urfave/cli/tree/ae84df4cef4a2a6f1a0cb1d41ea0f3af8755e5a8)
|
||||||
@ -541,7 +547,8 @@ 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.1.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.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
|
||||||
|
|
||||||
|
@ -1402,13 +1402,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())
|
||||||
@ -1424,28 +1426,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