1
0
Fork 0

Switch to QuestionHelper

pull/3983/head
Rob Bast 2015-04-30 12:23:13 +02:00
parent 290fafa156
commit 0fbc00f3fb
1 changed files with 45 additions and 51 deletions

View File

@ -78,8 +78,6 @@ EOT
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$dialog = $this->getHelperSet()->get('dialog');
$whitelist = array('name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license'); $whitelist = array('name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license');
$options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist))); $options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist)));
@ -107,16 +105,11 @@ EOT
} }
$file = new JsonFile('composer.json'); $file = new JsonFile('composer.json');
$json = $file->encode($options); $json = $file->encode($options);
if ($input->isInteractive()) { if ($input->isInteractive()) {
$this->getIO()->writeError(array( $this->getIO()->writeError(array('', $json, ''));
'', if (!$this->getIO()->askConfirmation('Do you confirm generation [<comment>yes</comment>]? ', true)) {
$json,
''
));
if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
$this->getIO()->writeError('<error>Command aborted</error>'); $this->getIO()->writeError('<error>Command aborted</error>');
return 1; return 1;
@ -135,7 +128,7 @@ EOT
if (!$this->hasVendorIgnore($ignoreFile)) { if (!$this->hasVendorIgnore($ignoreFile)) {
$question = 'Would you like the <info>vendor</info> directory added to your <info>.gitignore</info> [<comment>yes</comment>]? '; $question = 'Would you like the <info>vendor</info> directory added to your <info>.gitignore</info> [<comment>yes</comment>]? ';
if ($dialog->askConfirmation($output, $question, true)) { if ($this->getIO()->askConfirmation($question, true)) {
$this->addVendorIgnore($ignoreFile); $this->addVendorIgnore($ignoreFile);
} }
} }
@ -149,7 +142,6 @@ EOT
{ {
$git = $this->getGitConfig(); $git = $this->getGitConfig();
$dialog = $this->getHelperSet()->get('dialog');
$formatter = $this->getHelperSet()->get('formatter'); $formatter = $this->getHelperSet()->get('formatter');
$this->getIO()->writeError(array( $this->getIO()->writeError(array(
@ -189,9 +181,8 @@ EOT
} }
} }
$name = $dialog->askAndValidate( $name = $this->getIO()->askAndValidate(
$output, 'Package name (<vendor>/<name>) [<comment>'.$name.'</comment>]: ',
$dialog->getQuestion('Package name (<vendor>/<name>)', $name),
function ($value) use ($name) { function ($value) use ($name) {
if (null === $value) { if (null === $value) {
return $name; return $name;
@ -204,14 +195,15 @@ EOT
} }
return $value; return $value;
} },
null,
$name
); );
$input->setOption('name', $name); $input->setOption('name', $name);
$description = $input->getOption('description') ?: false; $description = $input->getOption('description') ?: false;
$description = $dialog->ask( $description = $this->getIO()->ask(
$output, 'Description [<comment>'.$description.'</comment>]: ',
$dialog->getQuestion('Description', $description),
$description $description
); );
$input->setOption('description', $description); $input->setOption('description', $description);
@ -223,22 +215,22 @@ EOT
} }
$self = $this; $self = $this;
$author = $dialog->askAndValidate( $author = $this->getIO()->askAndValidate(
$output, 'Author [<comment>'.$author.'</comment>]: ',
$dialog->getQuestion('Author', $author),
function ($value) use ($self, $author) { function ($value) use ($self, $author) {
$value = $value ?: $author; $value = $value ?: $author;
$author = $self->parseAuthorString($value); $author = $self->parseAuthorString($value);
return sprintf('%s <%s>', $author['name'], $author['email']); return sprintf('%s <%s>', $author['name'], $author['email']);
} },
null,
$author
); );
$input->setOption('author', $author); $input->setOption('author', $author);
$minimumStability = $input->getOption('stability') ?: ''; $minimumStability = $input->getOption('stability') ?: null;
$minimumStability = $dialog->askAndValidate( $minimumStability = $this->getIO()->askAndValidate(
$output, 'Minimum Stability [<comment>'.$minimumStability.'</comment>]: ',
$dialog->getQuestion('Minimum Stability', $minimumStability),
function ($value) use ($self, $minimumStability) { function ($value) use ($self, $minimumStability) {
if (null === $value) { if (null === $value) {
return $minimumStability; return $minimumStability;
@ -252,39 +244,38 @@ EOT
} }
return $value; return $value;
} },
null,
$minimumStability
); );
$input->setOption('stability', $minimumStability); $input->setOption('stability', $minimumStability);
$type = $input->getOption('type') ?: false; $type = $input->getOption('type') ?: false;
$type = $dialog->ask( $type = $this->getIO()->ask(
$output, 'Package Type [<comment>'.$type.'</comment>]: ',
$dialog->getQuestion('Package Type', $type),
$type $type
); );
$input->setOption('type', $type); $input->setOption('type', $type);
$license = $input->getOption('license') ?: false; $license = $input->getOption('license') ?: false;
$license = $dialog->ask( $license = $this->getIO()->ask(
$output, 'License [<comment>'.$license.'</comment>]: ',
$dialog->getQuestion('License', $license),
$license $license
); );
$input->setOption('license', $license); $input->setOption('license', $license);
$this->getIO()->writeError(array( $this->getIO()->writeError(array('', 'Define your dependencies.', ''));
'',
'Define your dependencies.',
''
));
$question = 'Would you like to define your dependencies (require) interactively [<comment>yes</comment>]? ';
$requirements = array(); $requirements = array();
if ($dialog->askConfirmation($output, $dialog->getQuestion('Would you like to define your dependencies (require) interactively', 'yes', '?'), true)) { if ($this->getIO()->askConfirmation($question, true)) {
$requirements = $this->determineRequirements($input, $output, $input->getOption('require')); $requirements = $this->determineRequirements($input, $output, $input->getOption('require'));
} }
$input->setOption('require', $requirements); $input->setOption('require', $requirements);
$question = 'Would you like to define your dev dependencies (require-dev) interactively [<comment>yes</comment>]? ';
$devRequirements = array(); $devRequirements = array();
if ($dialog->askConfirmation($output, $dialog->getQuestion('Would you like to define your dev dependencies (require-dev) interactively', 'yes', '?'), true)) { if ($this->getIO()->askConfirmation($question, true)) {
$devRequirements = $this->determineRequirements($input, $output, $input->getOption('require-dev')); $devRequirements = $this->determineRequirements($input, $output, $input->getOption('require-dev'));
} }
$input->setOption('require-dev', $devRequirements); $input->setOption('require-dev', $devRequirements);
@ -330,9 +321,6 @@ EOT
protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array()) protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array())
{ {
$dialog = $this->getHelperSet()->get('dialog');
$prompt = $dialog->getQuestion('Search for a package', false, ':');
if ($requires) { if ($requires) {
$requires = $this->normalizeRequirements($requires); $requires = $this->normalizeRequirements($requires);
$result = array(); $result = array();
@ -357,7 +345,7 @@ EOT
} }
$versionParser = new VersionParser(); $versionParser = new VersionParser();
while (null !== $package = $dialog->ask($output, $prompt)) { while (null !== $package = $this->getIO()->ask('Search for a package: ')) {
$matches = $this->findPackages($package); $matches = $this->findPackages($package);
if (count($matches)) { if (count($matches)) {
@ -410,7 +398,12 @@ EOT
throw new \Exception('Not a valid selection'); throw new \Exception('Not a valid selection');
}; };
$package = $dialog->askAndValidate($output, $dialog->getQuestion('Enter package # to add, or the complete package name if it is not listed', false, ':'), $validator, 3); $package = $this->getIO()->askAndValidate(
'Enter package # to add, or the complete package name if it is not listed: ',
$validator,
3,
false
);
} }
// no constraint yet, determine the best version automatically // no constraint yet, determine the best version automatically
@ -421,12 +414,13 @@ EOT
return $input ?: false; return $input ?: false;
}; };
$constraint = $dialog->askAndValidate( $constraint = $this->getIO()->askAndValidate(
$output, 'Enter the version constraint to require (or leave blank to use the latest version): ',
$dialog->getQuestion('Enter the version constraint to require (or leave blank to use the latest version)', false, ':'),
$validator, $validator,
3) 3,
; false
);
if (false === $constraint) { if (false === $constraint) {
$constraint = $this->findBestVersionForPackage($input, $package); $constraint = $this->findBestVersionForPackage($input, $package);