CLI and code improvements

This commit is contained in:
drygdryg 2020-09-03 06:02:22 +03:00
parent ee20fec1b4
commit 5886500006

View File

@ -535,7 +535,6 @@ proc generateAll(mac: string): seq[PinCode] =
when is_main_module:
from os import parseCmdLine
import argparse
let p = newParser("wpspin"):
@ -544,8 +543,8 @@ when is_main_module:
flag("-J", "--json", help = "return results in JSON representation")
arg("mac", help = "target MAC address to generate PIN code. Example: 11:22:33:44:55:66 or 11-22-33-44-55-66")
try:
let args = p.parse()
if (args.mac != "") and (not args.help):
let mac = args.mac.multiReplace(mac_separators_replace).toUpperAscii()
let pins = if args.get_all: generateAll(mac) else: generateSuggested(mac)
@ -564,3 +563,6 @@ when is_main_module:
echo &"{pin_value:<8} | {pin_name}"
else:
echo "No PINs found -- try to get all PINs (-A)"
except UsageError:
echo "Error: invalid arguments. Use -h to get help"
quit(QuitFailure)