@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"crypto/sha256"
5
5
"encoding/hex"
6
+ "encoding/json"
6
7
"fmt"
7
8
"io"
8
9
"log"
@@ -36,6 +37,12 @@ var debugLogger = log.New(os.Stderr, "", 0)
36
37
37
38
const unknownCommandMessage string = "unknown command"
38
39
40
+ type JsonErrorStruct struct {
41
+ Ok bool `json:"ok"`
42
+ ErrorMsg string `json:"error"`
43
+ Path string `json:"path"`
44
+ }
45
+
39
46
type HandleError int
40
47
41
48
const (
@@ -92,12 +99,12 @@ func runCommand(cmd *cobra.Command, args []string) error {
92
99
debugLogger .Println ("Running" , name )
93
100
94
101
if len (args ) > 0 {
95
- config .Set ("targetDirectory" , args [0 ])
102
+ config .Set (configuration . INPUT_DIRECTORY , args [0 ])
96
103
}
97
104
98
105
data , err := engine .Invoke (workflow .NewWorkflowIdentifier (name ))
99
106
if err == nil {
100
- _ , err = engine .InvokeWithInput (workflow . NewWorkflowIdentifier ( "output" ) , data )
107
+ _ , err = engine .InvokeWithInput (localworkflows . WORKFLOWID_OUTPUT_WORKFLOW , data )
101
108
} else {
102
109
debugLogger .Println ("Failed to execute the command!" , err )
103
110
}
@@ -255,7 +262,18 @@ func handleError(err error) HandleError {
255
262
func displayError (err error ) {
256
263
if err != nil {
257
264
if _ , ok := err .(* exec.ExitError ); ! ok {
258
- fmt .Println (err )
265
+ if config .GetBool (localworkflows .OUTPUT_CONFIG_KEY_JSON ) {
266
+ jsonError := JsonErrorStruct {
267
+ Ok : false ,
268
+ ErrorMsg : err .Error (),
269
+ Path : config .GetString (configuration .INPUT_DIRECTORY ),
270
+ }
271
+
272
+ jsonErrorBuffer , _ := json .MarshalIndent (jsonError , "" , " " )
273
+ fmt .Println (string (jsonErrorBuffer ))
274
+ } else {
275
+ fmt .Println (err )
276
+ }
259
277
}
260
278
}
261
279
}
0 commit comments