-
Notifications
You must be signed in to change notification settings - Fork 13
/
env.go
58 lines (46 loc) · 961 Bytes
/
env.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
package env
import (
"os"
"os/exec"
)
// CommandLocator ...
type CommandLocator interface {
LookPath(file string) (string, error)
}
type commandLocator struct{}
// NewCommandLocator ...
func NewCommandLocator() CommandLocator {
return commandLocator{}
}
// LookPath ...
func (l commandLocator) LookPath(file string) (string, error) {
return exec.LookPath(file)
}
// Repository ...
type Repository interface {
List() []string
Unset(key string) error
Get(key string) string
Set(key, value string) error
}
// NewRepository ...
func NewRepository() Repository {
return repository{}
}
type repository struct{}
// Get ...
func (d repository) Get(key string) string {
return os.Getenv(key)
}
// Set ...
func (d repository) Set(key, value string) error {
return os.Setenv(key, value)
}
// Unset ...
func (d repository) Unset(key string) error {
return os.Unsetenv(key)
}
// List ...
func (d repository) List() []string {
return os.Environ()
}