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

  1. import argparse
  2. from string import ascii_lowercase
  3. import cmd2
  4. from dictionary import DEFAULT, ALTERNATE
  5. LOWERCASE = set(ascii_lowercase)
  6. DICTS = {"default": DEFAULT, "alt": ALTERNATE}
  7. # argparsers
  8. dictionary_manage_parser = argparse.ArgumentParser()
  9. commands = dictionary_manage_parser.add_mutually_exclusive_group()
  10. commands.add_argument(
  11. "-l", "--list", action="store_true", help="List available dictionaries"
  12. )
  13. commands.add_argument("-s", "--switch", help="Dictionary to swap to")
  14. letter_set_manage = argparse.ArgumentParser()
  15. letter_set_manage.add_argument("new_letters")
  16. class MainLoop(cmd2.Cmd):
  17. """Loop for wordscape commands
  18. """
  19. prompt = "?$ "
  20. def __init__(self):
  21. self.dict = "default"
  22. self.letters = [l for l in input("Enter letters: ").lower() if l in LOWERCASE]
  23. self.prompt = ", ".join(self.letters) + " " + MainLoop.prompt
  24. super().__init__()
  25. @cmd2.with_argparser(dictionary_manage_parser)
  26. def do_dict(self, args):
  27. """list/switch dict"""
  28. if args.list:
  29. print(
  30. "\n".join(
  31. (
  32. "{} {}".format("*" if key == self.dict else " ", key)
  33. for key in DICTS.keys()
  34. )
  35. )
  36. )
  37. else:
  38. DICTS[args.switch]
  39. self.dict = args.switch
  40. @cmd2.with_argparser(letter_set_manage)
  41. def do_change_letters(self, args):
  42. pass
  43. if __name__ == "__main__":
  44. MainLoop().cmdloop()