Interactive management mode.
(file_path: str)
| 220 | |
| 221 | |
| 222 | def interactive_mode(file_path: str): |
| 223 | """Interactive management mode.""" |
| 224 | try: |
| 225 | with open(file_path, "r", encoding="utf-8") as f: |
| 226 | data = json.load(f) |
| 227 | except FileNotFoundError: |
| 228 | print(f"File not found, creating new: {file_path}") |
| 229 | data = {"images": []} |
| 230 | except json.JSONDecodeError as e: |
| 231 | print(f"ERROR: Invalid JSON: {e}") |
| 232 | return |
| 233 | |
| 234 | print(f"Loaded: {file_path}") |
| 235 | |
| 236 | while True: |
| 237 | print("\n=== Image Manager ===") |
| 238 | print("1. List images") |
| 239 | print("2. Show image details") |
| 240 | print("3. Add image") |
| 241 | print("4. Remove image") |
| 242 | print("5. Validate") |
| 243 | print("6. Save and exit") |
| 244 | print("7. Exit without saving") |
| 245 | |
| 246 | choice = input("\nChoice: ").strip() |
| 247 | |
| 248 | if choice == "1": |
| 249 | list_images(data) |
| 250 | elif choice == "2": |
| 251 | list_images(data) |
| 252 | try: |
| 253 | idx = int(input("Enter image index: ")) |
| 254 | show_image_details(data, idx) |
| 255 | except ValueError: |
| 256 | print("Invalid input") |
| 257 | elif choice == "3": |
| 258 | data = add_image(data) |
| 259 | elif choice == "4": |
| 260 | list_images(data) |
| 261 | try: |
| 262 | idx = int(input("Enter image index to remove: ")) |
| 263 | data = remove_image(data, idx) |
| 264 | except ValueError: |
| 265 | print("Invalid input") |
| 266 | elif choice == "5": |
| 267 | errors = validate_images_json(data) |
| 268 | if errors: |
| 269 | print(f"Validation FAILED with {len(errors)} error(s):") |
| 270 | for error in errors: |
| 271 | print(f" - {error}") |
| 272 | else: |
| 273 | print("Validation PASSED") |
| 274 | elif choice == "6": |
| 275 | save_json(data, file_path) |
| 276 | break |
| 277 | elif choice == "7": |
| 278 | print("Exiting without saving.") |
| 279 | break |
no test coverage detected