Code is all tore up

This commit is contained in:
2026-03-30 20:10:23 -04:00
parent 386455b1d0
commit e982fec1a4
19 changed files with 876 additions and 179 deletions

View File

@@ -20,19 +20,38 @@ def main():
print("Usage: ue-wingman.py ShowCommands [key=value ...]")
sys.exit(1)
msg = {"command": args[0]}
for arg in args[1:]:
key, _, value = arg.partition("=")
if value.lower() == "true":
value = True
elif value.lower() == "false":
value = False
else:
no_args_commands = {"ShowCommands", "UserManual"}
if len(args) == 1 and args[0] not in no_args_commands:
# No extra arguments: read JSON object from stdin.
# Accumulate lines and try to parse after each one.
decoder = json.JSONDecoder()
raw = ""
msg = None
for line in sys.stdin:
raw += line
try:
value = int(value)
except ValueError:
pass
msg[key] = value
msg, _ = decoder.raw_decode(raw.lstrip())
break
except json.JSONDecodeError:
continue
if msg is None:
print("Could not parse a complete JSON object from stdin")
sys.exit(1)
msg["command"] = args[0]
else:
msg = {"command": args[0]}
for arg in args[1:]:
key, _, value = arg.partition("=")
if value.lower() == "true":
value = True
elif value.lower() == "false":
value = False
else:
try:
value = int(value)
except ValueError:
pass
msg[key] = value
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(TIMEOUT)