mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
got rid of global MC variable
This commit is contained in:
parent
77337994ca
commit
15f237675f
2 changed files with 18 additions and 13 deletions
|
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "meshcore-cli"
|
name = "meshcore-cli"
|
||||||
version = "0.6.0"
|
version = "0.6.2"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
|
||||||
else :
|
else :
|
||||||
path_str = str(data['path_len'])
|
path_str = str(data['path_len'])
|
||||||
|
|
||||||
disp = f" {ANSI_GREEN}{name}"
|
disp = f"{ANSI_GREEN}{name}"
|
||||||
if 'signature' in data:
|
if 'signature' in data:
|
||||||
sender = mc.get_contact_by_key_prefix(data['signature'])
|
sender = mc.get_contact_by_key_prefix(data['signature'])
|
||||||
disp = disp + f"/{sender['adv_name']}"
|
disp = disp + f"/{sender['adv_name']}"
|
||||||
|
|
@ -99,7 +99,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
|
||||||
path_str = f"{ANSI_YELLOW}({data['path_len']}){ANSI_END}"
|
path_str = f"{ANSI_YELLOW}({data['path_len']}){ANSI_END}"
|
||||||
|
|
||||||
if above:
|
if above:
|
||||||
print_above(f" {ANSI_GREEN}ch{data['channel_idx']}({path_str}): {data['text']}")
|
print_above(f"{ANSI_GREEN}ch{data['channel_idx']}({path_str}): {data['text']}")
|
||||||
else:
|
else:
|
||||||
print(f"ch{data['channel_idx']}({path_str}): {data['text']}")
|
print(f"ch{data['channel_idx']}({path_str}): {data['text']}")
|
||||||
else:
|
else:
|
||||||
|
|
@ -108,7 +108,12 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
|
||||||
|
|
||||||
async def handle_message(event):
|
async def handle_message(event):
|
||||||
""" Process incoming message events """
|
""" Process incoming message events """
|
||||||
await process_event_message(MC, event, False, above=True)
|
await process_event_message(handle_message.mc, event,
|
||||||
|
above=handle_message.above, json_output=handle_message.json_output)
|
||||||
|
handle_message.json_output=False
|
||||||
|
handle_message.mc=None
|
||||||
|
handle_message.above=True
|
||||||
|
|
||||||
|
|
||||||
def make_completion_dict(contacts):
|
def make_completion_dict(contacts):
|
||||||
contact_list = {}
|
contact_list = {}
|
||||||
|
|
@ -935,7 +940,7 @@ async def process_cmds (mc, args, json_output=False) :
|
||||||
while cmds and len(cmds) > 0 :
|
while cmds and len(cmds) > 0 :
|
||||||
if not first and json_output :
|
if not first and json_output :
|
||||||
print(",")
|
print(",")
|
||||||
cmds = await next_cmd(MC, cmds, json_output)
|
cmds = await next_cmd(mc, cmds, json_output)
|
||||||
first = False
|
first = False
|
||||||
if json_output :
|
if json_output :
|
||||||
print("]")
|
print("]")
|
||||||
|
|
@ -1003,7 +1008,6 @@ def usage () :
|
||||||
|
|
||||||
async def main(argv):
|
async def main(argv):
|
||||||
""" Do the job """
|
""" Do the job """
|
||||||
global MC
|
|
||||||
json_output = JSON
|
json_output = JSON
|
||||||
debug = False
|
debug = False
|
||||||
address = ADDRESS
|
address = ADDRESS
|
||||||
|
|
@ -1065,10 +1069,11 @@ async def main(argv):
|
||||||
with open(MCCLI_ADDRESS, "w", encoding="utf-8") as f :
|
with open(MCCLI_ADDRESS, "w", encoding="utf-8") as f :
|
||||||
f.write(address)
|
f.write(address)
|
||||||
|
|
||||||
MC = MeshCore(con, debug=debug)
|
mc = MeshCore(con, debug=debug)
|
||||||
await MC.connect()
|
await mc.connect()
|
||||||
|
handle_message.mc = mc # connect meshcore to handle_message
|
||||||
|
|
||||||
res = await MC.commands.send_device_query()
|
res = await mc.commands.send_device_query()
|
||||||
if res.type == EventType.ERROR :
|
if res.type == EventType.ERROR :
|
||||||
logger.error(f"Error while querying device: {res}")
|
logger.error(f"Error while querying device: {res}")
|
||||||
return
|
return
|
||||||
|
|
@ -1077,14 +1082,14 @@ async def main(argv):
|
||||||
logger.setLevel(logging.ERROR)
|
logger.setLevel(logging.ERROR)
|
||||||
else :
|
else :
|
||||||
if res.payload["fw ver"] > 2 :
|
if res.payload["fw ver"] > 2 :
|
||||||
logger.info(f"Connected to {MC.self_info['name']} running on a {res.payload['ver']} fw.")
|
logger.info(f"Connected to {mc.self_info['name']} running on a {res.payload['ver']} fw.")
|
||||||
else :
|
else :
|
||||||
logger.info(f"Connected to {MC.self_info['name']}.")
|
logger.info(f"Connected to {mc.self_info['name']}.")
|
||||||
|
|
||||||
if len(args) == 0 : # no args, run in chat mode
|
if len(args) == 0 : # no args, run in chat mode
|
||||||
await process_cmds(MC, ["chat"], json_output)
|
await process_cmds(mc, ["chat"], json_output)
|
||||||
else:
|
else:
|
||||||
await process_cmds(MC, args, json_output)
|
await process_cmds(mc, args, json_output)
|
||||||
|
|
||||||
def cli():
|
def cli():
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue