protected function buildOptions(Package $package, InputInterface $input, OutputInterface $output) { $helper = $this->getHelperSet()->get('question'); $force_opts = $input->getOption('with-configure-options'); if ($force_opts) { if (!file_exists($force_opts) || !is_file($force_opts) || !is_readable($force_opts)) { throw new \Exception("File '{$force_opts}' is unusable"); } $force_opts = preg_replace(",\\s+,", ' ', file_get_contents($force_opts)); return [null, $force_opts]; } $options = $package->getConfigureOptions(); $optionsValue = []; foreach ($options as $name => $opt) { /* enable/with-<extname> */ if ($name == $package->getName() || str_replace('-', '_', $name) == $package->getName()) { $optionsValue[$name] = (object) ['type' => $opt->type, 'input' => true]; continue; } if ($input->getOption('defaults')) { $value = $opt->default; } else { if ($opt->type == 'enable') { $prompt = new ConfirmationQuestion($opt->prompt . ' (default: ' . ($opt->default ? 'yes' : 'no') . '): ', $opt->default); } else { $prompt = new Question($opt->prompt . ' (default: ' . ($opt->default ? $opt->default : '') . '): ', $opt->default); } $value = $helper->ask($input, $output, $prompt); } $optionsValue[$name] = (object) ['type' => $opt->type, 'input' => $value]; } return [$optionsValue, null]; }
public function showOptions(OutputInterface $output, Interfaces\Package $package) { $table = new Table($output); $table->setHeaders(['Type', 'Description', 'Default']); foreach ($package->getConfigureOptions() as $option) { $default = $option->default; if ($option->type === 'enable') { $option->type = '<fg=yellow>' . $option->type . '</fg=yellow>'; $default = $default ? '<fg=green>yes</fg=green>' : '<fg=red>no</fg=red>'; } $table->addRow([$option->type, wordwrap($option->prompt, 40, PHP_EOL), $default]); } $table->render(); }