Add `entry_point` command to `interface`. Parameters ---------- interface : click.Command or click.Group The click interface to augment with `entry_point`. entry_point : importlib.metadata.EntryPoint The entry point which loads to a ``click.Command`` or ``cli
(interface, entry_point)
| 162 | |
| 163 | |
| 164 | def _register_command_ep(interface, entry_point): |
| 165 | """Add `entry_point` command to `interface`. |
| 166 | |
| 167 | Parameters |
| 168 | ---------- |
| 169 | interface : click.Command or click.Group |
| 170 | The click interface to augment with `entry_point`. |
| 171 | entry_point : importlib.metadata.EntryPoint |
| 172 | The entry point which loads to a ``click.Command`` or |
| 173 | ``click.Group`` instance to be added as a sub-command or |
| 174 | sub-group in `interface`. |
| 175 | |
| 176 | """ |
| 177 | try: |
| 178 | command = entry_point.load() |
| 179 | except Exception as e: |
| 180 | warnings.warn( |
| 181 | f"While registering the command with name '{entry_point.name}', an " |
| 182 | f"exception occurred; {e}." |
| 183 | ) |
| 184 | return |
| 185 | if not isinstance(command, (click.Command, click.Group)): |
| 186 | warnings.warn( |
| 187 | "entry points in 'dask_cli' must be instances of " |
| 188 | f"click.Command or click.Group, not {type(command)}." |
| 189 | ) |
| 190 | return |
| 191 | |
| 192 | if command.name in interface.commands: |
| 193 | warnings.warn( |
| 194 | f"While registering the command with name '{command.name}', an " |
| 195 | "existing command or group; the original has been overwritten." |
| 196 | ) |
| 197 | |
| 198 | interface.add_command(command) |
| 199 | |
| 200 | |
| 201 | def run_cli(): |