def build_entry_point_args(command: click.Command, config: str, dry_run: Optional[str], integration_name: str, extra_args: Optional[str]) -> list[str]: args = ['--config', config] if dry_run is not None: args.append(dry_run) # if the integration_name is a known sub command, we add it right before the extra_args if integration_name and isinstance(command, click.MultiCommand) and \ command.get_command(None, integration_name): # type: ignore args.append(integration_name) if extra_args is not None: args.extend(extra_args.split()) return args
def _get_sub_commands(command: click.Command, ctx: click.Context) -> List[click.Command]: """Return subcommands of a Click command.""" subcommands = getattr(command, "commands", {}) if subcommands: return subcommands.values() if not isinstance(command, click.MultiCommand): return [] subcommands = [] for name in command.list_commands(ctx): subcommand = command.get_command(ctx, name) assert subcommand is not None subcommands.append(subcommand) return subcommands