function drush_init_application_global_options

master preflight.inc drush_init_application_global_options($container)
1 call to drush_init_application_global_options()
drush_preflight_prepare in includes/preflight.inc
Prepare Drush for preflight.

File

includes/preflight.inc, line 319
Preflight, postflight and shutdown code.

Code

function drush_init_application_global_options($container) {
  $application = $container->get('application');
  $definition = $application->getDefinition();

  // TODO: We should make a better way to manage global options
  $globalOptions = drush_get_global_options();

  foreach ($globalOptions as $option => $info) {
    $info +=['short-form' null];
    // TODO: We can't register options that Symfony has already registered,
    // but we need a better way than this.
    if (array_key_exists('symfony-conflict', $info)) {
      continue;
    }
    if ($info['short-form'] == 'n') {
      $info['short-form'] = null;
    }
    $description = $info['description'];
    $default = null;
    $mode = InputOption::VALUE_NONE;
    if (array_key_exists('example-value', $info)) {
      $mode = InputOption::VALUE_REQUIRED;
      // TODO: at the moment, global options do not know their default values,
      // but if they did, it would look like this:
      if (array_key_exists('default-value', $info)) {
        $default = $info['default-value'];
        $mode = InputOption::VALUE_OPTIONAL;
      }
    }
    // TODO: Any need to make use of InputOption::VALUE_IS_ARRAY?

    $definition->addOption(new InputOption("--$option", $info['short-form'], $mode, $description, $default));

    // TODO: If the default is TRUE, add a --no alias option.
    if ($default === TRUE) {
      $definition->addOption(new InputOption("--no-$option", null, $mode, "Negation of --$option.", FALSE));
    }
  }
}