Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UpdateConfigsCommand to prompt for which config tag to publish #984

Merged
21 changes: 17 additions & 4 deletions packages/framework/src/Console/Commands/UpdateConfigsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,31 @@ class UpdateConfigsCommand extends Command
/** @var string */
protected $description = 'Publish the default configuration files';

/** @var bool */
protected $hidden = true;

public function handle(): int
{
$options = [
'All configs',
'<comment>hyde-configs</comment>: Main configuration files',
'<comment>support-configs</comment>: Laravel and package configuration files',
];
$selection = $this->choice('Which configuration files do you want to publish?', $options, 'All configs');

$tag = $this->parseTagFromSelection($selection, $options);

Artisan::call('vendor:publish', [
'--tag' => 'configs',
'--tag' => $tag,
'--force' => true,
], $this->output);

$this->infoComment(sprintf('Published config files to [%s]', Hyde::path('config')));

return Command::SUCCESS;
}

protected function parseTagFromSelection(string $selection, array $options): string
{
$tags = ['configs', 'hyde-configs', 'support-configs'];

return $tags[array_search($selection, $options)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function tearDown(): void
public function test_command_has_expected_output()
{
$this->artisan('update:configs')
->expectsChoice('Which configuration files do you want to publish?', 'All configs', $this->expectedOptions())
->expectsOutput(sprintf('Published config files to [%s]', Hyde::path('config')))
->assertExitCode(0);
}
Expand All @@ -41,7 +42,9 @@ public function test_config_files_are_published()
{
$this->assertDirectoryDoesNotExist(Hyde::path('config'));

$this->artisan('update:configs')->assertExitCode(0);
$this->artisan('update:configs')
->expectsChoice('Which configuration files do you want to publish?', 'All configs', $this->expectedOptions())
->assertExitCode(0);

$this->assertFileEquals(Hyde::vendorPath('config/hyde.php'), Hyde::path('config/hyde.php'));

Expand All @@ -53,8 +56,19 @@ public function test_command_overwrites_existing_files()
File::makeDirectory(Hyde::path('config'));
File::put(Hyde::path('config/hyde.php'), 'foo');

$this->artisan('update:configs')->assertExitCode(0);
$this->artisan('update:configs')
->expectsChoice('Which configuration files do you want to publish?', 'All configs', $this->expectedOptions())
->assertExitCode(0);

$this->assertNotEquals('foo', File::get(Hyde::path('config/hyde.php')));
}

protected function expectedOptions(): array
{
return [
'All configs',
'<comment>hyde-configs</comment>: Main configuration files',
'<comment>support-configs</comment>: Laravel and package configuration files',
];
}
}