Skip to content

Commit

Permalink
Merge pull request #505 from rsteube/context-setenv
Browse files Browse the repository at this point in the history
context: setenv reference
  • Loading branch information
rsteube authored Apr 25, 2022
2 parents 9b62a16 + 7422593 commit 0e3153e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ type Context struct {
}

// Setenv sets the value of the environment variable named by the key.
func (c Context) Setenv(key, value string) Context {
func (c *Context) Setenv(key, value string) {
if c.Env == nil {
c.Env = []string{}
}
c.Env = append(c.Env, fmt.Sprintf("%v=%v", key, value))
return c
}

// Cache cashes values of a CompletionCallback for given duration and keys
Expand Down
4 changes: 3 additions & 1 deletion defaultActions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func TestActionExecCommandEnv(t *testing.T) {
return ActionValues()
}).Invoke(Context{})

c := Context{}
c.Setenv("carapace_TestActionExecCommand", "test")
ActionExecCommand("env")(func(output []byte) Action {
lines := strings.Split(string(output), "\n")
for _, line := range lines {
Expand All @@ -60,5 +62,5 @@ func TestActionExecCommandEnv(t *testing.T) {
}
t.Error("should contain env carapace_TestActionExecCommand=test")
return ActionValues()
}).Invoke(Context{}.Setenv("carapace_TestActionExecCommand", "test"))
}).Invoke(c)
}

0 comments on commit 0e3153e

Please sign in to comment.