(name, module, function, parent)
| 52 | |
| 53 | |
| 54 | def add_optional_command(name, module, function, parent): |
| 55 | try: |
| 56 | module = importlib.import_module(module, package="archery") |
| 57 | command = getattr(module, function) |
| 58 | except ImportError as exc: |
| 59 | error_message = exc.name |
| 60 | |
| 61 | @parent.command( |
| 62 | name, |
| 63 | context_settings={ |
| 64 | "allow_extra_args": True, |
| 65 | "ignore_unknown_options": True, |
| 66 | } |
| 67 | ) |
| 68 | def command(): |
| 69 | raise click.ClickException( |
| 70 | f"Couldn't import command `{name}` due to {error_message}" |
| 71 | ) |
| 72 | else: |
| 73 | parent.add_command(command) |