|
22 | 22 | MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/" |
23 | 23 | MCCLI_ADDRESS = MCCLI_CONFIG_DIR + "default_address" |
24 | 24 | MCCLI_HISTORY_FILE = MCCLI_CONFIG_DIR + "history" |
| 25 | +MCCLI_INIT_SCRIPT = MCCLI_CONFIG_DIR + "init" |
25 | 26 |
|
26 | 27 | # Fallback address if config file not found |
27 | 28 | # if None or "" then a scan is performed |
@@ -1064,14 +1065,23 @@ async def process_cmds (mc, args, json_output=False) : |
1064 | 1065 | first = True |
1065 | 1066 | if json_output : |
1066 | 1067 | print("[") |
1067 | | - while cmds and len(cmds) > 0 : |
| 1068 | + while cmds and len(cmds) > 0 and cmds[0][0] != '#' : |
1068 | 1069 | if not first and json_output : |
1069 | 1070 | print(",") |
1070 | 1071 | cmds = await next_cmd(mc, cmds, json_output) |
1071 | 1072 | first = False |
1072 | 1073 | if json_output : |
1073 | 1074 | print("]") |
1074 | 1075 |
|
| 1076 | +async def process_script(mc, file, json_output=False): |
| 1077 | + with open(file, "r") as f : |
| 1078 | + lines=f.readlines() |
| 1079 | + |
| 1080 | + for line in lines: |
| 1081 | + logger.debug(f"processing {line}") |
| 1082 | + cmds = shlex.split(line[:-1]) |
| 1083 | + await process_cmds(mc, cmds, json_output) |
| 1084 | + |
1075 | 1085 | def command_help(): |
1076 | 1086 | print(""" General commands |
1077 | 1087 | chat : enter the chat (interactive) mode |
@@ -1214,6 +1224,10 @@ async def main(argv): |
1214 | 1224 | else : |
1215 | 1225 | logger.info(f"Connected to {mc.self_info['name']}.") |
1216 | 1226 |
|
| 1227 | + if os.path.exists(MCCLI_INIT_SCRIPT) : |
| 1228 | + logger.debug(f"Executing init script : {MCCLI_INIT_SCRIPT}") |
| 1229 | + await process_script(mc, MCCLI_INIT_SCRIPT, json_output) |
| 1230 | + |
1217 | 1231 | if len(args) == 0 : # no args, run in chat mode |
1218 | 1232 | await process_cmds(mc, ["chat"], json_output) |
1219 | 1233 | else: |
|
0 commit comments