Skip to content

Commit 9f9ed3a

Browse files
committed
WIP docker:ci command
1 parent afb7a5e commit 9f9ed3a

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

src/Commands/DockerCiCommand.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,33 @@
44

55
use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\CiPlatform;
66
use BlameButton\LaravelDockerBuilder\Detectors\CiPlatformDetector;
7+
use Symfony\Component\Console\Input\InputArgument;
78

89
class DockerCiCommand extends BaseCommand
910
{
1011
protected $name = 'docker:ci';
1112

12-
protected $description = '';
13+
protected $description = 'Generate a CI file (supported: GitHub Actions, GitLab CI)';
1314

1415
public function handle(): int
1516
{
17+
if ($argument = $this->argument('ci-platform')) {
18+
if (!in_array($argument, CiPlatform::values())) {
19+
$this->error("Invalid value [$argument] for argument [ci-platform].");
20+
return self::FAILURE;
21+
}
22+
23+
return $this->copy($argument);
24+
}
25+
1626
$detected = app(CiPlatformDetector::class)->detect();
1727

18-
if (CiPlatform::GITLAB_CI === $detected) {
28+
return self::SUCCESS;
29+
}
30+
31+
protected function copy(string $platform): int
32+
{
33+
if (CiPlatform::GITLAB_CI === $platform) {
1934
$output = base_path('.gitlab-ci.yml');
2035

2136
if (file_exists($output)) {
@@ -31,4 +46,15 @@ public function handle(): int
3146

3247
return self::SUCCESS;
3348
}
49+
50+
protected function getArguments(): array
51+
{
52+
return [
53+
new InputArgument(
54+
name: 'ci-platform',
55+
mode: InputArgument::OPTIONAL,
56+
description: 'CI platform (supported: github, gitlab)',
57+
),
58+
];
59+
}
3460
}

src/Commands/GenerateQuestions/Choices/CiPlatform.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
class CiPlatform
66
{
7+
public const GITHUB_ACTIONS = 'github';
8+
79
public const GITLAB_CI = 'gitlab';
810

9-
public const GITHUB_ACTIONS = 'github';
11+
public static function values(): array
12+
{
13+
return [
14+
self::GITHUB_ACTIONS,
15+
self::GITLAB_CI,
16+
];
17+
}
1018
}

src/Commands/GenerateQuestions/NodeBuildToolQuestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getAnswer(BaseCommand $command): string
2323
if ($option = $command->option('node-build-tool')) {
2424
return in_array($option, NodeBuildTool::values())
2525
? $option
26-
: throw new InvalidOptionValueException("Invalid value [$option] for option [node-build-tool]");
26+
: throw new InvalidOptionValueException("Invalid value [$option] for option [node-build-tool].");
2727
}
2828

2929
$detected = app(NodeBuildToolDetector::class)->detect();

src/Commands/GenerateQuestions/NodePackageManagerQuestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getAnswer(BaseCommand $command): string|false
2323
if ($option = $command->option('node-package-manager')) {
2424
return in_array($option, NodePackageManager::values())
2525
? $option
26-
: throw new InvalidOptionValueException("Invalid value [$option] for option [node-package-manager]");
26+
: throw new InvalidOptionValueException("Invalid value [$option] for option [node-package-manager].");
2727
}
2828

2929
$detected = app(NodePackageManagerDetector::class)->detect();

src/Commands/GenerateQuestions/PhpVersionQuestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getAnswer(BaseCommand $command): string
2323
if ($option = $command->option('php-version')) {
2424
return in_array($option, PhpVersion::values())
2525
? $option
26-
: throw new InvalidOptionValueException("Invalid value [$option] for option [php-version]");
26+
: throw new InvalidOptionValueException("Invalid value [$option] for option [php-version].");
2727
}
2828

2929
$detected = app(PhpVersionDetector::class)->detect();

0 commit comments

Comments
 (0)