-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement.go
68 lines (56 loc) · 1.09 KB
/
element.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
package cloud_computer
import (
"fmt"
"strconv"
"strings"
)
// TODO: merge this and parse.Element
type Element struct {
GateName string
Part string
IsAlias bool
IsParameter bool
StaticValue bool
IsStaticValue bool
}
func (e Element) String() string {
es := []string{e.GateName}
if !e.IsAlias && e.Part != "" {
es = append(es, e.Part)
}
return strings.Join(es, ".")
}
func (e Element) Bash() string {
name := e.String()
if name == "" && e.IsStaticValue {
name = ""
if e.StaticValue == true {
name = "1"
} else {
name = "0"
}
return name
}
if name[0] == '$' && 7 <= len(name) && name[1:7] == "inputs" {
name = fmt.Sprintf("${i%s}", strings.ReplaceAll(name, "$inputs.", ""))
return name
}
return fmt.Sprintf("${name_variable}%s", name)
}
func parseElement(words ...string) Element {
if n, err := strconv.Atoi(words[0]); err == nil {
e := Element{
IsStaticValue: true,
}
if n == 0 {
e.StaticValue = false
} else {
e.StaticValue = true
}
return e
}
e := Element{
GateName: strings.Join(words, "."),
}
return e
}