Register a Click command for one CLI invoke, then put the group back.
(command)
| 63 | |
| 64 | @contextlib.contextmanager |
| 65 | def _temporary_command(command): |
| 66 | """Register a Click command for one CLI invoke, then put the group back.""" |
| 67 | original_callbacks = { |
| 68 | name: existing.callback for name, existing in celery.commands.items() |
| 69 | } |
| 70 | celery.add_command(command) |
| 71 | try: |
| 72 | yield |
| 73 | finally: |
| 74 | for name, callback in original_callbacks.items(): |
| 75 | existing = celery.commands.get(name) |
| 76 | if existing is not None: |
| 77 | existing.callback = callback |
| 78 | celery.commands.pop(command.name, None) |
| 79 | |
| 80 | |
| 81 | def _on_preload(received): |
no test coverage detected