Merge pull request #741 from corruptmemory/expose-value

Exposed the `value` accessor in `Context`
This commit is contained in:
lynn [they] 2019-11-18 12:07:22 -08:00 committed by GitHub
commit 108d39a38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -114,8 +114,8 @@ func (c *Context) Lineage() []*Context {
return lineage return lineage
} }
// value returns the value of the flag corresponding to `name` // Value returns the value of the flag corresponding to `name`
func (c *Context) value(name string) interface{} { func (c *Context) Value(name string) interface{} {
return c.flagSet.Lookup(name).Value.(flag.Getter).Get() return c.flagSet.Lookup(name).Value.(flag.Getter).Get()
} }

View File

@ -3,8 +3,8 @@ package cli
import ( import (
"context" "context"
"flag" "flag"
"sort"
"os" "os"
"sort"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -328,7 +328,7 @@ func TestContextPropagation(t *testing.T) {
parent := NewContext(nil, nil, nil) parent := NewContext(nil, nil, nil)
parent.Context = context.WithValue(context.Background(), "key", "val") parent.Context = context.WithValue(context.Background(), "key", "val")
ctx := NewContext(nil, nil, parent) ctx := NewContext(nil, nil, parent)
val := ctx.Value("key") val := ctx.Context.Value("key")
if val == nil { if val == nil {
t.Fatal("expected a parent context to be inherited but got nil") t.Fatal("expected a parent context to be inherited but got nil")
} }

View File

@ -121,8 +121,8 @@ func TestFlagsFromEnv(t *testing.T) {
a := App{ a := App{
Flags: []Flag{test.flag}, Flags: []Flag{test.flag},
Action: func(ctx *Context) error { Action: func(ctx *Context) error {
if !reflect.DeepEqual(ctx.value(test.flag.Names()[0]), test.output) { if !reflect.DeepEqual(ctx.Value(test.flag.Names()[0]), test.output) {
t.Errorf("ex:%01d expected %q to be parsed as %#v, instead was %#v", i, test.input, test.output, ctx.value(test.flag.Names()[0])) t.Errorf("ex:%01d expected %q to be parsed as %#v, instead was %#v", i, test.input, test.output, ctx.Value(test.flag.Names()[0]))
} }
return nil return nil
}, },