Skip to content

Commit 83b0a82

Browse files
committed
Updated installer to use --destination option instead of an argument.
1 parent 3cc049b commit 83b0a82

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

.vortex/installer/src/Command/InstallCommand.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use DrevOps\VortexInstaller\Utils\Strings;
1818
use DrevOps\VortexInstaller\Utils\Tui;
1919
use Symfony\Component\Console\Command\Command;
20-
use Symfony\Component\Console\Input\InputArgument;
2120
use Symfony\Component\Console\Input\InputInterface;
2221
use Symfony\Component\Console\Input\InputOption;
2322
use Symfony\Component\Console\Output\OutputInterface;
@@ -31,7 +30,7 @@
3130
*/
3231
class InstallCommand extends Command {
3332

34-
const ARG_DESTINATION = 'destination';
33+
const OPTION_DESTINATION = 'destination';
3534

3635
const OPTION_ROOT = 'root';
3736

@@ -87,23 +86,22 @@ protected function configure(): void {
8786
$this->setDescription('Install Vortex from remote or local repository.');
8887
$this->setHelp(<<<EOF
8988
Interactively install Vortex from the latest stable release into the current directory:
90-
php installer destination
89+
php installer --destination=.
9190
9291
Non-interactively install Vortex from the latest stable release into the specified directory:
93-
php installer --no-interaction destination
92+
php installer --no-interaction --destination=path/to/destination
9493
9594
Install Vortex from the stable branch into the specified directory:
96-
php installer --uri=https://github.com/drevops/vortex.git@stable destination
95+
php installer --uri=https://github.com/drevops/vortex.git@stable --destination=path/to/destination
9796
9897
Install Vortex from a specific release into the specified directory:
99-
php installer --uri=https://github.com/drevops/[email protected] destination
98+
php installer --uri=https://github.com/drevops/[email protected] --destination=path/to/destination
10099
101100
Install Vortex from a specific commit into the specified directory:
102-
php installer --uri=https://github.com/drevops/vortex.git@abcd123 destination
101+
php installer --uri=https://github.com/drevops/vortex.git@abcd123 --destination=path/to/destination
103102
EOF
104103
);
105-
$this->addArgument(static::ARG_DESTINATION, InputArgument::OPTIONAL, 'Destination directory. Optional. Defaults to the current directory.');
106-
104+
$this->addOption(static::OPTION_DESTINATION, NULL, InputOption::VALUE_REQUIRED, 'Destination directory. Defaults to the current directory.');
107105
$this->addOption(static::OPTION_ROOT, NULL, InputOption::VALUE_REQUIRED, 'Path to the root for file path resolution. If not specified, current directory is used.');
108106
$this->addOption(static::OPTION_NO_INTERACTION, 'n', InputOption::VALUE_NONE, 'Do not ask any interactive question.');
109107
$this->addOption(static::OPTION_CONFIG, 'c', InputOption::VALUE_REQUIRED, 'A JSON string with options or a path to a JSON file.');
@@ -116,8 +114,7 @@ protected function configure(): void {
116114
* {@inheritdoc}
117115
*/
118116
protected function execute(InputInterface $input, OutputInterface $output): int {
119-
// @see https://github.com/drevops/vortex/issues/1502
120-
if ($input->getOption('help') || $input->getArgument('destination') == 'help') {
117+
if ($input->getOption('help')) {
121118
$output->write($this->getHelp());
122119

123120
return Command::SUCCESS;
@@ -286,7 +283,7 @@ protected function resolveOptions(array $arguments, array $options): void {
286283
}
287284

288285
// Set destination directory.
289-
$dst = !empty($arguments['destination']) && is_scalar($arguments[static::ARG_DESTINATION]) ? strval($arguments[static::ARG_DESTINATION]) : NULL;
286+
$dst = !empty($options[static::OPTION_DESTINATION]) && is_scalar($options[static::OPTION_DESTINATION]) ? strval($options[static::OPTION_DESTINATION]) : NULL;
290287
$dst = $dst ?: Env::get(Config::DST, $this->config->get(Config::DST, $this->config->get(Config::ROOT)));
291288
$dst = File::realpath($dst);
292289
$this->config->set(Config::DST, $dst, TRUE);

.vortex/installer/tests/Functional/Command/InstallCommandTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public function testInstallCommand(
9090

9191
if ($download_should_fail) {
9292
$mock_downloader = $this->createMock(Downloader::class);
93-
$mock_downloader->method('download')
94-
->willThrowException(new \RuntimeException('Failed to download Vortex.'));
93+
$mock_downloader->method('download')->willThrowException(new \RuntimeException('Failed to download Vortex.'));
9594
$command->setDownloader($mock_downloader);
9695
}
9796
else {
@@ -112,7 +111,7 @@ public function testInstallCommand(
112111
$build_command->setRunner($build_runner);
113112
$this->applicationGet()->add($build_command);
114113

115-
$command_inputs[InstallCommand::ARG_DESTINATION] = self::$sut;
114+
$command_inputs['--' . InstallCommand::OPTION_DESTINATION] = self::$sut;
116115

117116
$this->applicationRun($command_inputs, [], $expect_failure);
118117

.vortex/installer/tests/Functional/FunctionalTestCase.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ protected function tearDown(): void {
8585
protected function runNonInteractiveInstall(?string $dst = NULL, array $options = [], bool $expect_fail = FALSE): void {
8686
$dst ??= static::$sut;
8787

88-
if ($dst !== '' && $dst !== '0') {
89-
$args[InstallCommand::ARG_DESTINATION] = $dst;
90-
}
91-
9288
$defaults = [
9389
InstallCommand::OPTION_NO_INTERACTION => TRUE,
9490
InstallCommand::OPTION_URI => File::dir(static::$root),
9591
];
92+
93+
if ($dst !== '' && $dst !== '0') {
94+
$defaults[InstallCommand::OPTION_DESTINATION] = $dst;
95+
}
96+
9697
$options += $defaults;
9798

9899
foreach ($options as $option => $value) {
@@ -110,7 +111,7 @@ protected function runInteractiveInstall(array $answers = [], ?string $dst = NUL
110111
$this->runNonInteractiveInstall($dst, $options + [InstallCommand::OPTION_NO_INTERACTION => FALSE], $expect_fail);
111112
}
112113

113-
protected function assertSutContains(string|array $needles): void {
114+
protected function assertSutContains(string | array $needles): void {
114115
$needles = is_array($needles) ? $needles : [$needles];
115116

116117
foreach ($needles as $needle) {
@@ -127,7 +128,7 @@ protected function assertSutContains(string|array $needles): void {
127128
}
128129
}
129130

130-
protected function assertSutNotContains(string|array $needles): void {
131+
protected function assertSutNotContains(string | array $needles): void {
131132
$needles = is_array($needles) ? $needles : [$needles];
132133

133134
foreach ($needles as $needle) {

.vortex/tests/phpunit/Traits/SutTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function runInstaller(array $arguments = []): void {
7979

8080
$arguments = array_merge([
8181
'--no-interaction',
82-
static::locationsSut(),
82+
'--destination'=> static::locationsSut(),
8383
], $arguments);
8484

8585
$this->logNote('Run the installer script');

0 commit comments

Comments
 (0)