You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
import argparse
|
|
from string import ascii_lowercase
|
|
import cmd2
|
|
|
|
from dictionary import DEFAULT, ALTERNATE
|
|
|
|
LOWERCASE = set(ascii_lowercase)
|
|
DICTS = {"default": DEFAULT, "alt": ALTERNATE}
|
|
# argparsers
|
|
dictionary_manage_parser = argparse.ArgumentParser()
|
|
commands = dictionary_manage_parser.add_mutually_exclusive_group()
|
|
commands.add_argument(
|
|
"-l", "--list", action="store_true", help="List available dictionaries"
|
|
)
|
|
commands.add_argument("-s", "--switch", help="Dictionary to swap to")
|
|
|
|
letter_set_manage = argparse.ArgumentParser()
|
|
letter_set_manage.add_argument("new_letters")
|
|
|
|
|
|
class MainLoop(cmd2.Cmd):
|
|
"""Loop for wordscape commands
|
|
|
|
"""
|
|
|
|
prompt = "?$ "
|
|
|
|
def __init__(self):
|
|
self.dict = "default"
|
|
self.letters = [l for l in input("Enter letters: ").lower() if l in LOWERCASE]
|
|
self.prompt = ", ".join(self.letters) + " " + MainLoop.prompt
|
|
super().__init__()
|
|
|
|
@cmd2.with_argparser(dictionary_manage_parser)
|
|
def do_dict(self, args):
|
|
"""list/switch dict"""
|
|
if args.list:
|
|
print(
|
|
"\n".join(
|
|
(
|
|
"{} {}".format("*" if key == self.dict else " ", key)
|
|
for key in DICTS.keys()
|
|
)
|
|
)
|
|
)
|
|
else:
|
|
DICTS[args.switch]
|
|
self.dict = args.switch
|
|
|
|
@cmd2.with_argparser(letter_set_manage)
|
|
def do_change_letters(self, args):
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
MainLoop().cmdloop()
|