-
Notifications
You must be signed in to change notification settings - Fork 31
/
environment.go
57 lines (44 loc) · 866 Bytes
/
environment.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
package tachyon
import (
"errors"
"io/ioutil"
"os"
)
type Environment struct {
Vars Scope
report Reporter
config *Config
tmpDir string
Paths Paths
}
func NewEnv(s Scope, cfg *Config) *Environment {
e := new(Environment)
e.report = sCLIReporter
e.Vars = s
e.config = cfg
d, err := ioutil.TempDir("", "tachyon")
if err == nil {
e.tmpDir = d
}
e.Paths = SimplePath{"."}
return e
}
func (e *Environment) ReportJSON() {
e.report = sJsonChunkReporter
}
var eNoTmpDir = errors.New("No tempdir available")
func (e *Environment) TempFile(prefix string) (*os.File, error) {
if e.tmpDir == "" {
return nil, eNoTmpDir
}
dest, err := ioutil.TempFile(e.tmpDir, prefix)
return dest, err
}
func (e *Environment) Cleanup() {
os.RemoveAll(e.tmpDir)
}
func (e *Environment) SetPaths(n Paths) Paths {
cur := e.Paths
e.Paths = n
return cur
}