Skip to content

Commit d268da5

Browse files
committed
init script
1 parent edfc6e4 commit d268da5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/meshcore_cli/meshcore_cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/"
2323
MCCLI_ADDRESS = MCCLI_CONFIG_DIR + "default_address"
2424
MCCLI_HISTORY_FILE = MCCLI_CONFIG_DIR + "history"
25+
MCCLI_INIT_SCRIPT = MCCLI_CONFIG_DIR + "init"
2526

2627
# Fallback address if config file not found
2728
# if None or "" then a scan is performed
@@ -1064,14 +1065,23 @@ async def process_cmds (mc, args, json_output=False) :
10641065
first = True
10651066
if json_output :
10661067
print("[")
1067-
while cmds and len(cmds) > 0 :
1068+
while cmds and len(cmds) > 0 and cmds[0][0] != '#' :
10681069
if not first and json_output :
10691070
print(",")
10701071
cmds = await next_cmd(mc, cmds, json_output)
10711072
first = False
10721073
if json_output :
10731074
print("]")
10741075

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+
10751085
def command_help():
10761086
print(""" General commands
10771087
chat : enter the chat (interactive) mode
@@ -1214,6 +1224,10 @@ async def main(argv):
12141224
else :
12151225
logger.info(f"Connected to {mc.self_info['name']}.")
12161226

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+
12171231
if len(args) == 0 : # no args, run in chat mode
12181232
await process_cmds(mc, ["chat"], json_output)
12191233
else:

0 commit comments

Comments
 (0)