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.

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