-
Notifications
You must be signed in to change notification settings - Fork 9
/
variables.go
69 lines (60 loc) · 1.66 KB
/
variables.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gexe
import (
"github.com/vladimirvivien/gexe/vars"
)
// Variables returns the variable mapping for echo session e
func (e *Echo) Variables() *vars.Variables {
return e.vars
}
// Envs declares environment variables using
// a multi-line space-separated list:
//
// Envs("GOOS=linux" "GOARCH=amd64", `platform="$GOOS:$GOARCH"`)
//
// Environment vars can be used in string values
// using Eval("building for os=$GOOS")
func (e *Echo) Envs(variables ...string) *Echo {
vars := e.vars.Envs(variables...)
e.err = vars.Err()
return e
}
// SetEnv sets a global process environment variable.
func (e *Echo) SetEnv(name, value string) *Echo {
vars := e.vars.SetEnv(name, value)
e.err = vars.Err()
return e
}
// Vars declares multiple session-scope variables using
// string literal format:
//
// Envs("foo=bar", "platform=amd64", `"data="info ${platform}"`)
//
// Note that session vars are only available
// for the running process.
func (e *Echo) Vars(variables ...string) *Echo {
vars := e.vars.Vars(variables...)
e.err = vars.Err()
return e
}
// SetVar declares a session variable.
func (e *Echo) SetVar(name, value string) *Echo {
vars := e.vars.SetVar(name, value)
e.err = vars.Err()
return e
}
// UnsetVar removes a session variable.
func (e *Echo) UnsetVar(name string) *Echo {
vars := e.vars.UnsetVar(name)
e.err = vars.Err()
return e
}
// Val retrieves a session or environment variable
func (e *Echo) Val(name string) string {
return e.vars.Val(name)
}
// Eval returns the string str with its content expanded
// with variable values i.e. Eval("I am $HOME") returns
// "I am </user/home/path>"
func (e *Echo) Eval(str string) string {
return e.vars.Eval(str)
}