Beispiel #1
0
 def set_card_type():
     """
     Keeps prompting a user with a card type option until a user gives
     a valid answer, and returns the selected card type.
     :return: CardType
     """
     card_types = {}
     count = 0
     question = "\nWhich type of card would you like to add?\n"
     for type_ in CardType:
         card_types[count] = type_
         count += 1
         question += f"\t{count}. {type_.value}\n"
     question += "Please select a card type: "
     input_type = None
     while input_type is None:
         try:
             answer = input(question)
             InputHandler.validate_input(len(card_types), answer)
         except ValueError:
             print("\nPlease type an integer!")
         except CommandNotFoundException as e:
             print(f"{e}")
         else:
             input_type = card_types[int(answer) - 1]
             return input_type
Beispiel #2
0
 def run_program(self):
     """
     Prompts a user with a various options until a user types 'exit'.
     """
     commands = [
         self.print_all_cards, self.print_cards_by_type, self.add_card,
         self.search_card, self.delete_card_by_id, self.delete_card_by_name,
         self.backup_card_list
     ]
     EXIT = "exit"
     want_to_exit = False
     while not want_to_exit:
         answer = input(f"\nWhat would you like to do?\n"
                        f"\t1. Show all cards in the app\n"
                        f"\t2. Show all cards of a specific type\n"
                        f"\t3. Add a new card\n"
                        f"\t4. Search for a card\n"
                        f"\t5. Delete a card by ID\n"
                        f"\t6. Delete a card by Name\n"
                        f"\t7. Back up all cards in the app\n"
                        f"Please select or type '{EXIT}' to exit: ")
         if answer == EXIT:
             print("\nBye!")
             want_to_exit = True
         else:
             try:
                 InputHandler.validate_input(len(commands), answer)
             except ValueError:
                 print("\nPlease type an integer!")
             except CommandNotFoundException as e:
                 print(f"{e}")
             else:
                 commands[int(answer) - 1]()