-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
scope.go
42 lines (35 loc) · 1023 Bytes
/
scope.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
package sandbox
import (
"fmt"
"os"
"strings"
)
type Scope struct {
scopedTasksInStack []*ScopedFlow
}
func NewScope(tasksInScope []*ScopedFlow) *Scope {
return &Scope{
scopedTasksInStack: tasksInScope,
}
}
func (s *Scope) String() string {
result := []string{}
for _, flow := range s.scopedTasksInStack {
str := flow.Path()
result = append(result, str)
}
return strings.Join(result, ",")
}
func (s Scope) FindFlowAtPath(path string) (*ScopedFlow, error) {
e := s.scopedTasksInStack[len(s.scopedTasksInStack)-1]
os.Stderr.WriteString(fmt.Sprintf("%s -> %s\n", e.Path(), path))
for _, scoped := range s.scopedTasksInStack {
if found, err := scoped.FindFlowByPathComponents(strings.Split(path, ".")); err == nil {
os.Stderr.WriteString(fmt.Sprintf(" %s -> %s [found %s]\n", scoped.Path(), path, found))
return found, nil
} else {
os.Stderr.WriteString(fmt.Sprintf(" %s -> %s [not found]\n", scoped.Path(), path))
}
}
return nil, fmt.Errorf("No expr found at path \"%s\"", path)
}