From c0c07a7e163f8ccca167914a8fbe36341bf25c20 Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Fri, 30 Jun 2017 07:30:53 -0400 Subject: [PATCH] Fix #2460. Use $application instead of $command in option verify Thus removing some no longer needed code from annotation_adapter.inc --- includes/annotationcommand_adapter.inc | 65 ++++++-------------------- includes/command.inc | 19 ++++++-- 2 files changed, 30 insertions(+), 54 deletions(-) diff --git a/includes/annotationcommand_adapter.inc b/includes/annotationcommand_adapter.inc index 8ef481e6b3..42c972af60 100644 --- a/includes/annotationcommand_adapter.inc +++ b/includes/annotationcommand_adapter.inc @@ -452,25 +452,9 @@ function annotationcommand_adapter_get_commands_for_commandhandler($commandhandl } } // $command['required-arguments'] = $required_arguments; - foreach ($commandinfo->options()->getValues() as $option => $default) { - $description = $commandinfo->options()->getDescription($option); - $command['options'][$option] = ['description' => $description]; - if (!empty($default)) { - $command['options'][$option]['example-value'] = $default; - } - $fn = 'annotationcommand_adapter_alter_option_description_' . $option; - if (function_exists($fn)) { - $command['options'][$option] = $fn($command['options'][$option], $commandinfo, $default); - } - if ($option == 'fields') { - // Allow these options to pass validation - https://github.com/drush-ops/drush/issues/2825 - $command['options']['field'] = 'Select just one field, and force format to \'string\''; - $command['options']['include-field-labels'] = 'Set to 0 to avoid field labels in output.'; - } - if ($commandinfo->getAnnotation('hidden-options') == $option) { - $command['options'][$option]['hidden'] = TRUE; - } - } + + // _drush_verify_cli_options() uses $application so nothing to do here. + $command['annotations'] = $commandinfo->getAnnotations(); // If the command has a '@return' annotation, then // remember information we will need to use the output formatter. @@ -491,6 +475,17 @@ function annotationcommand_adapter_get_commands_for_commandhandler($commandhandl return $commands; } +/** + * Determine whether command record represents an Annotated command. + * + * @param array $command + * + * @return bool + */ +function annotation_adapter_is_annotated(array $command) { + return !empty($command['annotated-command-callback']); +} + /** * Add legacy commands to the $application. Used by help and list commands. * @@ -500,7 +495,7 @@ function annotationcommand_adapter_get_commands_for_commandhandler($commandhandl function annotation_adapter_add_legacy_commands_to_application($application) { $commands = drush_get_commands(); foreach ($commands as $command) { - if (empty($command['annotated-command-callback']) && empty($command['hidden'])) { + if (!annotation_adapter_is_annotated($command) && empty($command['hidden'])) { $annotated = new AnnotatedCommand($command['command']); $annotated->setDescription($command['description']); $annotated->setAliases($command['aliases']); @@ -842,36 +837,6 @@ function annotationcommand_adapter_call_validate_interface($names, $hooks, Comma return true; } -/** - * Alter the value of the --format description. Show available formats. - */ -function annotationcommand_adapter_alter_option_description_format($option_help, $commandinfo, $default) { - $formatterManager = annotatedcomand_adapter_get_formatter(); - $return_type = $commandinfo->getReturnType(); - if (!empty($return_type)) { - $available_formats = $formatterManager->validFormats($return_type); - $option_help['description'] = dt('Select output format. Available: !formats.', array('!formats' => implode(', ', $available_formats))); - if (!empty($default)) { - $option_help['description'] .= dt(' Default is !default.', array('!default' => $default)); - } - } - return $option_help; -} - -/** - * Add the available fields list to --fields description. - */ -function annotationcommand_adapter_alter_option_description_fields($option_help, $commandinfo, $default) { - $formatOptions = new FormatterOptions($commandinfo->getAnnotations()->getArrayCopy()); - $field_labels = $formatOptions->get(FormatterOptions::FIELD_LABELS, [], ''); - $default_fields = $formatOptions->get(FormatterOptions::DEFAULT_FIELDS, [], array_keys($field_labels)); - $available_fields = array_keys($field_labels); - // @todo silencing a notice that will likely be fixed on views-list fixes https://github.com/consolidation/output-formatters/issues/35 - $option_help['example-value'] = @implode(', ', $default_fields); - $option_help['description'] = dt('Fields to output. All available fields are: !available.', array('!available' => implode(', ', $available_fields))); - return $option_help; -} - /** * In some circumstances, Drush just does a deep search for any *.drush.inc * file, so that it can find all commands, in enabled and disabled modules alike, diff --git a/includes/command.inc b/includes/command.inc index 21e9ef98c3..863d51800c 100644 --- a/includes/command.inc +++ b/includes/command.inc @@ -523,11 +523,22 @@ function drush_handle_command_output($command, $structured_output) { */ function _drush_verify_cli_options($command) { - // Start out with just the options in the current command record. - $options = _drush_get_command_options($command); + if (annotation_adapter_is_annotated($command)) { + // The canonical options list is now in $application + $application = Drush::getApplication(); + annotation_adapter_add_legacy_commands_to_application($application); + $console = $application->get($command['command']); + $options = $console->getDefinition()->getOptions(); + // Add formatter options. See \Consolidation\OutputFormatters\Options\FormatterOptions + // @todo Move this out of Drush. + $options['include-field-labels'] = ''; + } + else { + // Start out with just the options in the current command record. + $options = _drush_get_command_options($command); + } + // Skip all tests if the command is marked to allow anything. - // Also skip backend commands, which may have options on the commandline - // that were inherited from the calling command. if (($command['allow-additional-options'] === TRUE)) { return TRUE; }