Skip to content

Commit

Permalink
Fixes #469: Users are confused with default options when generating a…
Browse files Browse the repository at this point in the history
…n SSH key or creating an IDE. (acquia#471)

* Fixes #469: Users are confused with default options when generating an SSH key or creating an IDE.

* Add message about default value.

* Standarize question format.

* Standardize.

* Fix test.
  • Loading branch information
grasmash authored Mar 10, 2021
1 parent 8113589 commit 3471183
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Command/Auth/AuthLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function determineApiSecret(InputInterface $input, OutputInterface $ou
$this->validateApiKey($api_secret);
}
else {
$question = new Question('<question>Please enter your API Secret:</question> ');
$question = new Question('Please enter your API Secret');
$question->setHidden($this->localMachineHelper->useTty());
$question->setHiddenFallback(TRUE);
$question->setValidator(\Closure::fromCallable([$this, 'validateApiKey']));
Expand Down
6 changes: 4 additions & 2 deletions src/Command/Ide/IdeCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use React\EventLoop\Factory;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;

/**
* Class IdeCreateCommand.
Expand Down Expand Up @@ -59,11 +60,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$account_resource = new Account($acquia_cloud_client);
$account = $account_resource->get();
$default = "{$account->first_name} {$account->last_name}'s IDE";
$ide_label = $this->io->ask('Please enter a label for your Cloud IDE', $default);
$ides_resource = new Ides($acquia_cloud_client);
$question = new Question("Please enter a label for your Cloud IDE. Press enter to use default", $default);
$ide_label = $this->io->askQuestion($question);

// Create it.
$this->checklist->addItem('Creating your Cloud IDE');
$ides_resource = new Ides($acquia_cloud_client);
$response = $ides_resource->create($cloud_application_uuid, $ide_label);
$this->checklist->completePreviousItem();

Expand Down
8 changes: 5 additions & 3 deletions src/Command/Ssh/SshKeyCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ protected function execute(InputInterface $input, OutputInterface $output) {
*
* @return string
* @throws \Acquia\Cli\Exception\AcquiaCliException
* @throws \Exception
*/
protected function createSshKey($input, OutputInterface $output): string {
$filename = $this->determineFilename($input, $output);
$password = $this->determinePassword($input, $output);

$filepath = $this->sshDir . '/' . $filename;
if (file_exists($filepath)) {
throw new AcquiaCliException('An SSH key with the filename {filepath} already exists. Please delete it and retry.', ['filepath' => $filepath]);
throw new AcquiaCliException('An SSH key with the filename {filepath} already exists. Please delete it and retry', ['filepath' => $filepath]);
}

$process = $this->localMachineHelper->execute([
Expand Down Expand Up @@ -88,7 +89,8 @@ protected function determineFilename(InputInterface $input, OutputInterface $out
$this->validateFilename($filename);
}
else {
$question = new Question('<question>Please enter a filename for your new local SSH key:</question> ', 'id_rsa_acquia');
$default = 'id_rsa_acquia';
$question = new Question("Please enter a filename for your new local SSH key. Press enter to use default value", $default);
$question->setNormalizer(static function ($value) {
return $value ? trim($value) : '';
});
Expand Down Expand Up @@ -130,7 +132,7 @@ protected function determinePassword(InputInterface $input, OutputInterface $out
$this->validatePassword($password);
}
else {
$question = new Question('<question>Enter a password for your SSH key:</question> ');
$question = new Question('Enter a password for your SSH key');
$question->setHidden($this->localMachineHelper->useTty());
$question->setNormalizer(static function ($value) {
return $value ? trim($value) : '';
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Ssh/SshKeyDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function determineCloudKey($acquia_cloud_client) {
$cloud_keys,
'uuid',
'label',
'<question>Choose an SSH key to delete from the Cloud Platform</question>:'
'Choose an SSH key to delete from the Cloud Platform'
);
return $cloud_key;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Ssh/SshKeyUploadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function promptChooseLocalSshKey($local_keys): string {
$labels[] = $local_key->getFilename();
}
$question = new ChoiceQuestion(
'<question>Choose a local SSH key to upload to the Cloud Platform:</question>',
'Choose a local SSH key to upload to the Cloud Platform',
$labels
);
return $this->io->askQuestion($question);
Expand All @@ -121,7 +121,7 @@ protected function determineSshKeyLabel(InputInterface $input, OutputInterface $
$label = $this->validateSshKeyLabel($label);
}
else {
$question = new Question('<question>Please enter a Cloud Platform label for this SSH key:</question> ');
$question = new Question('Please enter a Cloud Platform label for this SSH key');
$question->setNormalizer(Closure::fromCallable([$this, 'normalizeSshKeyLabel']));
$question->setValidator(Closure::fromCallable([$this, 'validateSshKeyLabel']));
$label = $this->io->askQuestion($question);
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/src/Commands/Ide/IdeCreateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function testCreate(): void {
$this->assertStringContainsString('Please select a Cloud Platform application:', $output);
$this->assertStringContainsString(' [0] Sample application 1', $output);
$this->assertStringContainsString(' [1] Sample application 2', $output);
$this->assertStringContainsString("Please enter a label for your Cloud IDE [Jane Doe's IDE]", $output);
$this->assertStringContainsString("Please enter a label for your Cloud IDE", $output);
$this->assertStringContainsString("[Jane Doe's IDE]", $output);
$this->assertStringContainsString('Your IDE is ready!', $output);
$this->assertStringContainsString('Your IDE URL: https://215824ff-272a-4a8c-9027-df32ed1d68a9.ides.acquia.com', $output);
$this->assertStringContainsString('Your Drupal Site URL: https://ide-215824ff-272a-4a8c-9027-df32ed1d68a9.prod.acquia-sites.com', $output);
Expand Down

0 comments on commit 3471183

Please sign in to comment.