@@ -15,6 +15,7 @@ import (
1515 "github.com/numary/ledger/config"
1616 "github.com/numary/ledger/ledger"
1717 "github.com/numary/ledger/storage"
18+ "github.com/numary/machine/script/compiler"
1819 "github.com/spf13/cobra"
1920 "github.com/spf13/viper"
2021 "go.uber.org/fx"
@@ -91,7 +92,7 @@ func Execute() {
9192 },
9293 })
9394
94- script := & cobra.Command {
95+ script_exec := & cobra.Command {
9596 Use : "exec [ledger] [script]" ,
9697 Args : cobra .ExactArgs (2 ),
9798 Run : func (cmd * cobra.Command , args []string ) {
@@ -135,15 +136,49 @@ func Execute() {
135136 log .Fatal (err )
136137 }
137138
138- fmt .Println (res .StatusCode , string (b ))
139+ var result struct {
140+ Err string `json:"err,omitempty"`
141+ Ok bool `json:"ok"`
142+ }
143+ err = json .Unmarshal (b , & result )
144+ if err != nil {
145+ log .Fatal (err )
146+ }
147+ if result .Ok {
148+ fmt .Println ("Script ran successfully ✅" )
149+ } else {
150+ log .Fatal (result .Err )
151+ }
152+ },
153+ }
154+
155+ script_check := & cobra.Command {
156+ Use : "check [script]" ,
157+ Args : cobra .ExactArgs (1 ),
158+ Run : func (cmd * cobra.Command , args []string ) {
159+ config .Init ()
160+
161+ b , err := ioutil .ReadFile (args [0 ])
162+
163+ if err != nil {
164+ log .Fatal (err )
165+ }
166+
167+ _ , err = compiler .Compile (string (b ))
168+ if err != nil {
169+ log .Fatal (err )
170+ } else {
171+ fmt .Println ("Script is correct ✅" )
172+ }
139173 },
140174 }
141175
142176 root .AddCommand (server )
143177 root .AddCommand (conf )
144178 root .AddCommand (UICmd )
145179 root .AddCommand (store )
146- root .AddCommand (script )
180+ root .AddCommand (script_exec )
181+ root .AddCommand (script_check )
147182
148183 if err := root .Execute (); err != nil {
149184 fmt .Fprintln (os .Stderr , err )
0 commit comments