@@ -3,6 +3,7 @@ package main
33import (
44 "crypto/sha256"
55 "encoding/hex"
6+ "encoding/json"
67 "fmt"
78 "io"
89 "log"
@@ -36,6 +37,12 @@ var debugLogger = log.New(os.Stderr, "", 0)
3637
3738const unknownCommandMessage string = "unknown command"
3839
40+ type JsonErrorStruct struct {
41+ Ok bool `json:"ok"`
42+ ErrorMsg string `json:"error"`
43+ Path string `json:"path"`
44+ }
45+
3946type HandleError int
4047
4148const (
@@ -92,12 +99,12 @@ func runCommand(cmd *cobra.Command, args []string) error {
9299 debugLogger .Println ("Running" , name )
93100
94101 if len (args ) > 0 {
95- config .Set ("targetDirectory" , args [0 ])
102+ config .Set (configuration . INPUT_DIRECTORY , args [0 ])
96103 }
97104
98105 data , err := engine .Invoke (workflow .NewWorkflowIdentifier (name ))
99106 if err == nil {
100- _ , err = engine .InvokeWithInput (workflow . NewWorkflowIdentifier ( "output" ) , data )
107+ _ , err = engine .InvokeWithInput (localworkflows . WORKFLOWID_OUTPUT_WORKFLOW , data )
101108 } else {
102109 debugLogger .Println ("Failed to execute the command!" , err )
103110 }
@@ -255,7 +262,18 @@ func handleError(err error) HandleError {
255262func displayError (err error ) {
256263 if err != nil {
257264 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+ }
259277 }
260278 }
261279}
0 commit comments