Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed the value accessor in Context #741

Merged
merged 2 commits into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions context.go
Expand Up @@ -114,8 +114,8 @@ func (c *Context) Lineage() []*Context {
return lineage
}

// value returns the value of the flag corresponding to `name`
func (c *Context) value(name string) interface{} {
// Value returns the value of the flag corresponding to `name`
func (c *Context) Value(name string) interface{} {
return c.flagSet.Lookup(name).Value.(flag.Getter).Get()
}

Expand Down
4 changes: 2 additions & 2 deletions context_test.go
Expand Up @@ -3,8 +3,8 @@ package cli
import (
"context"
"flag"
"sort"
"os"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestContextPropagation(t *testing.T) {
parent := NewContext(nil, nil, nil)
parent.Context = context.WithValue(context.Background(), "key", "val")
ctx := NewContext(nil, nil, parent)
val := ctx.Value("key")
val := ctx.Context.Value("key")
if val == nil {
t.Fatal("expected a parent context to be inherited but got nil")
}
Expand Down
4 changes: 2 additions & 2 deletions flag_test.go
Expand Up @@ -121,8 +121,8 @@ func TestFlagsFromEnv(t *testing.T) {
a := App{
Flags: []Flag{test.flag},
Action: func(ctx *Context) error {
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]))
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]))
}
return nil
},
Expand Down