mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
init script
This commit is contained in:
parent
edfc6e4256
commit
d268da599f
1 changed files with 15 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ from meshcore import MeshCore, EventType, logger
|
|||
MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/"
|
||||
MCCLI_ADDRESS = MCCLI_CONFIG_DIR + "default_address"
|
||||
MCCLI_HISTORY_FILE = MCCLI_CONFIG_DIR + "history"
|
||||
MCCLI_INIT_SCRIPT = MCCLI_CONFIG_DIR + "init"
|
||||
|
||||
# Fallback address if config file not found
|
||||
# if None or "" then a scan is performed
|
||||
|
|
@ -1064,7 +1065,7 @@ async def process_cmds (mc, args, json_output=False) :
|
|||
first = True
|
||||
if json_output :
|
||||
print("[")
|
||||
while cmds and len(cmds) > 0 :
|
||||
while cmds and len(cmds) > 0 and cmds[0][0] != '#' :
|
||||
if not first and json_output :
|
||||
print(",")
|
||||
cmds = await next_cmd(mc, cmds, json_output)
|
||||
|
|
@ -1072,6 +1073,15 @@ async def process_cmds (mc, args, json_output=False) :
|
|||
if json_output :
|
||||
print("]")
|
||||
|
||||
async def process_script(mc, file, json_output=False):
|
||||
with open(file, "r") as f :
|
||||
lines=f.readlines()
|
||||
|
||||
for line in lines:
|
||||
logger.debug(f"processing {line}")
|
||||
cmds = shlex.split(line[:-1])
|
||||
await process_cmds(mc, cmds, json_output)
|
||||
|
||||
def command_help():
|
||||
print(""" General commands
|
||||
chat : enter the chat (interactive) mode
|
||||
|
|
@ -1214,6 +1224,10 @@ async def main(argv):
|
|||
else :
|
||||
logger.info(f"Connected to {mc.self_info['name']}.")
|
||||
|
||||
if os.path.exists(MCCLI_INIT_SCRIPT) :
|
||||
logger.debug(f"Executing init script : {MCCLI_INIT_SCRIPT}")
|
||||
await process_script(mc, MCCLI_INIT_SCRIPT, json_output)
|
||||
|
||||
if len(args) == 0 : # no args, run in chat mode
|
||||
await process_cmds(mc, ["chat"], json_output)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue