-
Notifications
You must be signed in to change notification settings - Fork 21
/
commandLineBinding.go
107 lines (84 loc) · 3.15 KB
/
commandLineBinding.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package cwl
import (
"fmt"
//"github.com/davecgh/go-spew/spew"
"reflect"
"github.com/mitchellh/mapstructure"
)
//http://www.commonwl.org/v1.0/Workflow.html#CommandLineBinding
type CommandLineBinding struct {
LoadContents bool `yaml:"loadContents,omitempty" bson:"loadContents,omitempty" json:"loadContents,omitempty" mapstructure:"loadContents,omitempty"`
Position int `yaml:"position,omitempty" bson:"position,omitempty" json:"position,omitempty" mapstructure:"position,omitempty"`
Prefix string `yaml:"prefix,omitempty" bson:"prefix,omitempty" json:"prefix,omitempty" mapstructure:"prefix,omitempty"`
Separate bool `yaml:"separate,omitempty" bson:"separate,omitempty" json:"separate,omitempty" mapstructure:"separate,omitempty"`
ItemSeparator string `yaml:"itemSeparator,omitempty" bson:"itemSeparator,omitempty" json:"itemSeparator,omitempty" mapstructure:"itemSeparator,omitempty"`
ValueFrom *Expression `yaml:"valueFrom,omitempty" bson:"valueFrom,omitempty" json:"valueFrom,omitempty" mapstructure:"valueFrom,omitempty"`
ShellQuote bool `yaml:"shellQuote,omitempty" bson:"shellQuote,omitempty" json:"shellQuote,omitempty" mapstructure:"shellQuote,omitempty"`
}
func NewCommandLineBinding(original interface{}) (clb *CommandLineBinding, err error) {
var commandlinebinding CommandLineBinding
original, err = MakeStringMap(original)
if err != nil {
return
}
switch original.(type) {
case map[string]interface{}:
original_map, ok := original.(map[string]interface{})
if !ok {
err = fmt.Errorf("(NewCommandLineBinding) type assertion error map[string]interface{}")
return
}
value_from, ok := original_map["valueFrom"]
if ok {
exp, xerr := NewExpression(value_from)
if xerr != nil {
err = fmt.Errorf("(NewCommandLineBinding) NewExpression failed: %s", xerr.Error())
return
}
original_map["valueFrom"] = *exp
}
err = mapstructure.Decode(original, &commandlinebinding)
if err != nil {
err = fmt.Errorf("(NewCommandLineBinding) mapstructure: %s", err.Error())
return
}
case string:
org_str, _ := original.(string)
commandlinebinding.ValueFrom, err = NewExpression(org_str)
if err != nil {
return
}
default:
err = fmt.Errorf("(NewCommandLineBinding) type %s unknown", reflect.TypeOf(original))
return
}
clb = &commandlinebinding
return
}
func NewCommandLineBindingArray(original interface{}) (new_array []CommandLineBinding, err error) {
switch original.(type) {
case []interface{}:
for _, v := range original.([]interface{}) {
clb, xerr := NewCommandLineBinding(v)
if xerr != nil {
err = fmt.Errorf("(NewCommandLineBindingArray) []interface{} NewCommandLineBinding returned: %s", xerr.Error())
return
}
//fmt.Printf("C")
new_array = append(new_array, *clb)
//fmt.Printf("D")
}
return
case string:
clb, xerr := NewCommandLineBinding(original)
if xerr != nil {
err = fmt.Errorf("(NewCommandLineBindingArray) string NewCommandLineBinding returned: %s", xerr.Error())
return
}
new_array = append(new_array, *clb)
default:
err = fmt.Errorf("(NewCommandLineBindingArray) type unknown")
return
}
return
}