/** * {@inheritdoc} */ public function execute($name = NULL) { if (empty($this->assets)) { return; } $options = array_keys($this->assets); $options[] = dt('All'); $choice = 'all'; if ($this->count > 2 && !drush_get_option('all')) { $choice = drush_choice($options, dt('Choose which asset from @name to view:', array('@name' => $this->project->getInfo('name')))); } else { drush_print(dt("Number of @name asset(s): @count\n", array('@name' => $this->project->getInfo('name'), '@count' => $this->count))); } if ($choice === FALSE) { return; } elseif ($choice === $this->count) { $this->clearScreen(); $choice = 'all'; } if ($choice !== FALSE && $choice !== 'all') { $this->clearScreen(); $this->printAsset($options[$choice]); $this->execute($name); } elseif ($this->count || $choice === 'all') { foreach ($this->notice as $key => $asset) { $this->printAsset($key); } return; } }
/** * Select the most appropriate release for a project, based on a strategy. * * @param Array &$request * A request array. * The array will be expanded with the project type. * @param String $restrict_to * One of: * 'dev': Forces choosing a -dev release. * 'version': Forces choosing a point release. * '': No restriction. * Default is ''. * @param String $select * Strategy for selecting a release, should be one of: * - auto: Try to select the latest release, if none found allow the user * to choose. * - always: Force the user to choose a release. * - never: Try to select the latest release, if none found then fail. * - ignore: Ignore and return NULL. * If no supported release is found, allow to ask the user to choose one. * @param Boolean $all * In case $select = TRUE this indicates that all available releases will be * offered the user to choose. * * @return array * The selected release. */ public function selectReleaseBasedOnStrategy($request, $restrict_to = '', $select = 'never', $all = FALSE, $version = NULL) { if (!in_array($select, array('auto', 'never', 'always', 'ignore'))) { return drush_set_error('DRUSH_PM_UNKNOWN_SELECT_STRATEGY', dt("Error: select strategy must be one of: auto, never, always, ignore", array())); } $project_release_info = $this->get($request); if (!$project_release_info) { return FALSE; } if ($select != 'always') { if (isset($request['version'])) { $release = $project_release_info->getSpecificRelease($request['version']); if ($release === FALSE) { return drush_set_error('DRUSH_PM_COULD_NOT_FIND_VERSION', dt("Could not locate !project version !version.", array('!project' => $request['name'], '!version' => $request['version']))); } } if ($restrict_to == 'dev') { // If you specified a specific release AND --dev, that is either // redundant (okay), or contradictory (error). if (!empty($release)) { if ($release['version_extra'] != 'dev') { return drush_set_error('DRUSH_PM_COULD_NOT_FIND_VERSION', dt("You requested both --dev and !project version !version, which is not a '-dev' release.", array('!project' => $request['name'], '!version' => $request['version']))); } } else { $release = $project_release_info->getDevRelease(); if ($release === FALSE) { return drush_set_error('DRUSH_PM_NO_DEV_RELEASE', dt('There is no development release for project !project.', array('!project' => $request['name']))); } } } // If there was no specific release requested, try to identify the most appropriate release. if (empty($release)) { $release = $project_release_info->getRecommendedOrSupportedRelease(); } if ($release) { return $release; } else { $message = dt('There are no stable releases for project !project.', array('!project' => $request['name'])); if ($select == 'never') { return drush_set_error('DRUSH_PM_NO_STABLE_RELEASE', $message); } drush_log($message, 'warning'); if ($select == 'ignore') { return NULL; } } } // At this point the only chance is to ask the user to choose a release. if ($restrict_to == 'dev') { $filter = 'dev'; } elseif ($all) { $filter = 'all'; } else { $filter = ''; } $releases = $project_release_info->filterReleases($filter, $version); $options = array(); foreach ($releases as $release) { $options[$release['version']] = array($release['version'], '-', gmdate('Y-M-d', $release['date']), '-', implode(', ', $release['release_status'])); } $choice = drush_choice($options, dt('Choose one of the available releases for !project:', array('!project' => $request['name']))); if (!$choice) { return drush_user_abort(); } return $releases[$choice]; }