From 454dc8091ec40016ef693772830e6ae781cb84f3 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Wed, 13 May 2020 09:25:56 -0700 Subject: [PATCH] coresendmsg: small usage cleanup, removed printing enum values when listing tlvs, updated examples to use current expected values --- daemon/scripts/coresendmsg | 45 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/daemon/scripts/coresendmsg b/daemon/scripts/coresendmsg index a909522f..9f5fa776 100755 --- a/daemon/scripts/coresendmsg +++ b/daemon/scripts/coresendmsg @@ -19,7 +19,7 @@ def print_available_tlvs(t, tlv_class): """ print(f"TLVs available for {t} message:") for tlv in sorted([tlv for tlv in tlv_class.tlv_type_map], key=lambda x: x.name): - print(f"{tlv.value}:{tlv.name}") + print(tlv.name) def print_examples(name): @@ -27,27 +27,26 @@ def print_examples(name): Print example usage of this script. """ examples = [ - ("link n1number=2 n2number=3 delay=15000", - "set a 15ms delay on the link between n2 and n3"), - ("link n1number=2 n2number=3 guiattr=\"color=blue\"", - "change the color of the link between n2 and n3"), - ("node number=3 xpos=125 ypos=525", + ("NODE NUMBER=3 X_POSITION=125 Y_POSITION=525", "move node number 3 to x,y=(125,525)"), - ("node number=4 icon=/usr/local/share/core/icons/normal/router_red.gif", + ("NODE NUMBER=4 ICON=/usr/local/share/core/icons/normal/router_red.gif", "change node number 4\"s icon to red"), - ("node flags=add number=5 type=0 name=\"n5\" xpos=500 ypos=500", + ("NODE flags=ADD NUMBER=5 TYPE=0 NAME=\"n5\" X_POSITION=500 Y_POSITION=500", "add a new router node n5"), - ("link flags=add n1number=4 n2number=5 if1ip4=\"10.0.3.2\" " \ - "if1ip4mask=24 if2ip4=\"10.0.3.1\" if2ip4mask=24", + ("LINK N1_NUMBER=2 N2_NUMBER=3 DELAY=15000", + "set a 15ms delay on the link between n2 and n3"), + ("LINK N1_NUMBER=2 N2_NUMBER=3 GUI_ATTRIBUTES=\"color=blue\"", + "change the color of the link between n2 and n3"), + ("LINK flags=ADD N1_NUMBER=4 N2_NUMBER=5 INTERFACE1_IP4=\"10.0.3.2\" " + "INTERFACE1_IP4_MASK=24 INTERFACE2_IP4=\"10.0.3.1\" INTERFACE2_IP4_MASK=24", "link node n5 with n4 using the given interface addresses"), - ("exec flags=str,txt node=1 num=1000 cmd=\"uname -a\" -l", + ("EXECUTE flags=STRING,TEXT NODE=1 NUMBER=1000 COMMAND=\"uname -a\" -l", "run a command on node 1 and wait for the result"), - ("exec node=2 num=1001 cmd=\"killall ospfd\"", + ("EXECUTE NODE=2 NUMBER=1001 COMMAND=\"killall ospfd\"", "run a command on node 2 and ignore the result"), - ("file flags=add node=1 name=\"/var/log/test.log\" data=\"Hello World.\"", + ("FILE flags=ADD NODE=1 NAME=\"/var/log/test.log\" DATA=\"Hello World.\"", "write a test.log file on node 1 with the given contents"), - ("file flags=add node=2 name=\"test.log\" " \ - "srcname=\"./test.log\"", + ("FILE flags=ADD NODE=2 NAME=\"test.log\" SOURCE_NAME=\"./test.log\"", "move a test.log file from host to node 2"), ] print(f"Example {name} invocations:") @@ -154,10 +153,14 @@ def main(): """ types = [message_type.name for message_type in MessageTypes] flags = [flag.name for flag in MessageFlags] - usagestr = "usage: %prog [-h|-H] [options] [message-type] [flags=flags] " - usagestr += "[message-TLVs]\n\n" - usagestr += f"Supported message types:\n {types}\n" - usagestr += f"Supported message flags (flags=f1,f2,...):\n {flags}" + types_usage = " ".join(types) + flags_usage = " ".join(flags) + usagestr = ( + "usage: %prog [-h|-H] [options] [message-type] [flags=flags] " + "[message-TLVs]\n\n" + f"Supported message types:\n {types_usage}\n" + f"Supported message flags (flags=f1,f2,...):\n {flags_usage}" + ) parser = optparse.OptionParser(usage=usagestr) default_address = "localhost" default_session = None @@ -188,9 +191,9 @@ def main(): help=f"Use TCP instead of UDP and connect to a session default: {default_tcp}") def usage(msg=None, err=0): - sys.stdout.write("\n") + print() if msg: - sys.stdout.write(msg + "\n\n") + print(f"{msg}\n") parser.print_help() sys.exit(err)