@@ -597,14 +597,24 @@ async def next_cmd(mc, cmds, json_output=False):
597597 print_snr <on/off> : toggle snr display in messages""" )
598598 case "print_name" :
599599 interactive_loop .print_name = (cmds [2 ] == "on" )
600+ if json_output :
601+ print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
600602 case "classic_prompt" :
601603 interactive_loop .classic = (cmds [2 ] == "on" )
604+ if json_output :
605+ print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
602606 case "color" :
603607 process_event_message .color = (cmds [2 ] == "on" )
608+ if json_output :
609+ print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
604610 case "print_snr" :
605611 process_event_message .print_snr = (cmds [2 ] == "on" )
612+ if json_output :
613+ print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
606614 case "json_msgs" :
607615 handle_message .json_output = (cmds [2 ] == "on" )
616+ if json_output :
617+ print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
608618 case "pin" :
609619 res = await mc .commands .set_devicepin (cmds [2 ])
610620 logger .debug (res )
@@ -1220,16 +1230,12 @@ async def next_cmd(mc, cmds, json_output=False):
12201230
12211231async def process_cmds (mc , args , json_output = False ) :
12221232 cmds = args
1223- first = True
1224- if json_output :
1225- print ("[" )
12261233 while cmds and len (cmds ) > 0 and cmds [0 ][0 ] != '#' :
1227- if not first and json_output :
1234+ if not process_cmds . first and json_output :
12281235 print ("," )
12291236 cmds = await next_cmd (mc , cmds , json_output )
1230- first = False
1231- if json_output :
1232- print ("]" )
1237+ process_cmds .first = False
1238+ process_cmds .first = True
12331239
12341240async def process_script (mc , file , json_output = False ):
12351241 with open (file , "r" ) as f :
@@ -1291,7 +1297,7 @@ def usage () :
12911297
12921298 Arguments :
12931299 -h : prints this help
1294- -j : json output
1300+ -j : json output (disables init file)
12951301 -D : debug
12961302 -S : performs a ble scan and ask for device
12971303 -l : list available ble devices and exit
@@ -1419,14 +1425,18 @@ async def main(argv):
14191425 else :
14201426 logger .info (f"Connected to { mc .self_info ['name' ]} ." )
14211427
1422- if os .path .exists (MCCLI_INIT_SCRIPT ) :
1428+ if os .path .exists (MCCLI_INIT_SCRIPT ) and not json_output :
14231429 logger .debug (f"Executing init script : { MCCLI_INIT_SCRIPT } " )
14241430 await process_script (mc , MCCLI_INIT_SCRIPT , json_output )
14251431
14261432 if len (args ) == 0 : # no args, run in chat mode
14271433 await process_cmds (mc , ["chat" ], json_output )
14281434 else :
1435+ if json_output :
1436+ print ("[" )
14291437 await process_cmds (mc , args , json_output )
1438+ if json_output :
1439+ print ("]" )
14301440
14311441def cli ():
14321442 try :
0 commit comments