def select_deployment_to_run(env_name, deployments=None, command='build'):  # noqa pylint: disable=too-many-branches,too-many-statements,too-many-locals
        """Query user for deployments to run."""
        if deployments is None or not deployments:
            return []
        deployments_to_run = []

        num_deployments = len(deployments)

        if num_deployments == 1:
            selected_deployment_index = 1
        else:
            print('')
            print('Configured deployments:')
            for i, deployment in enumerate(deployments):
                print(" %d: %s" % (i+1, _deployment_menu_entry(deployment)))
            print('')
            print('')
            if command == 'destroy':
                print('(Operating in destroy mode -- "all" will destroy all '
                      'deployments in reverse order)')
            selected_deployment_index = input('Enter number of deployment to run (or "all"): ')

        if selected_deployment_index == 'all':
            return deployments
        if selected_deployment_index == '':
            LOGGER.error('Please select a valid number (or "all")')
            sys.exit(1)

        selected_deployment = deployments[int(selected_deployment_index) - 1]
        if selected_deployment.get('current_dir', False):
            deployments_to_run.append(selected_deployment)
        elif not selected_deployment.get('modules', []):
            LOGGER.error('No modules configured in selected deployment')
            sys.exit(1)
        elif len(selected_deployment['modules']) == 1:
            # No need to select a module in the deployment - there's only one
            if command == 'destroy':
                LOGGER.info('(only one deployment detected; all modules '
                            'automatically selected for termination)')
                if not strtobool(input('Proceed?: ')):
                    sys.exit(0)
            deployments_to_run.append(selected_deployment)
        else:
            modules = selected_deployment['modules']
            print('')
            print('Configured modules in deployment \'%s\':' % selected_deployment.get('name'))
            for i, module in enumerate(modules):
                print(" %s: %s" % (i+1, _module_menu_entry(module, env_name)))
            print('')
            print('')
            if command == 'destroy':
                print('(Operating in destroy mode -- "all" will destroy all '
                      'deployments in reverse order)')
            selected_module_index = input('Enter number of module to run (or "all"): ')
            if selected_module_index == 'all':
                deployments_to_run.append(selected_deployment)
            elif selected_module_index == '' or (
                    not selected_module_index.isdigit() or (
                        not 0 < int(selected_module_index) <= len(modules))):
                LOGGER.error('Please select a valid number (or "all")')
                sys.exit(1)
            else:
                selected_deployment['modules'] = [modules[int(selected_module_index) - 1]]
                deployments_to_run.append(selected_deployment)

        LOGGER.debug('Selected deployment is %s...', deployments_to_run)
        return deployments_to_run
Query user for deployments to run.