Skip to content

Commit f4ebee3

Browse files
committed
Use reference to Eval to judge if it's nil
1 parent c026adc commit f4ebee3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

binding.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Binding struct {
1616
ValueFrom *Alias `json:"valueFrom"`
1717
// CommandOutputBinding
1818
Glob []string `json:"glob"`
19-
Eval Eval `json:"outputEval"`
19+
Eval *Eval `json:"outputEval"`
2020
Contents bool `json:"loadContents"`
2121
}
2222

@@ -42,7 +42,7 @@ func (binding Binding) New(i interface{}) *Binding {
4242
case "valueFrom":
4343
dest.ValueFrom = &Alias{v.(string)}
4444
case "outputEval":
45-
dest.Eval = Eval{v.(string)}
45+
dest.Eval = &Eval{v.(string)}
4646
}
4747
}
4848
}

output.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,39 @@ func (outs Outputs) LoadContents(srcdir string) (*otto.Otto, error) {
145145
// Dump ...
146146
func (outs Outputs) Dump(vm *otto.Otto, dir string, stdout, stderr string, w io.Writer) error {
147147

148-
dest := map[string]map[string]interface{}{}
148+
dest := map[string]interface{}{}
149149
for _, o := range outs {
150+
if o.Binding != nil && o.Binding.Eval != nil && vm != nil {
151+
js, err := o.Binding.Eval.ToJavaScriptString()
152+
if err != nil {
153+
return err
154+
}
155+
v, err := vm.Run(js)
156+
if err != nil {
157+
return err
158+
}
159+
switch {
160+
case v.IsNumber():
161+
dest[o.ID], err = v.ToInteger()
162+
if err != nil {
163+
return err
164+
}
165+
default:
166+
// TODO: more type switch
167+
}
168+
// TODO: do we need integrate all the outputs?
169+
return jsonindent.NewEncoder(w).Encode(dest)
170+
}
150171
if err := o.DumpFileMeta(dest, dir, stdout, stderr, w); err != nil {
151172
return err
152173
}
153174
}
175+
154176
return nil
155177
}
156178

157179
// DumpFileMeta ...
158-
func (o Output) DumpFileMeta(dest map[string]map[string]interface{}, dir string, stdout, stderr string, w io.Writer) error {
180+
func (o Output) DumpFileMeta(dest map[string]interface{}, dir string, stdout, stderr string, w io.Writer) error {
159181

160182
// This output should not be dumped
161183
if o.Binding != nil && o.Binding.LoadContents {

0 commit comments

Comments
 (0)