Skip to content

Commit

Permalink
Add choice + deprecated commands
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed Jun 4, 2024
1 parent 425c835 commit c532e34
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/Command/InitializeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

final class InitializeCommand extends Command
{
private const array ALLOWED_TYPES = [
"symfony",
"library",
];
private const array LEGACY_COMMANDS = [
"init-symfony",
"init-library",
];

/**
*/
public function __construct ()
Expand All @@ -26,15 +35,13 @@ protected function configure () : void
{
$this
->setDescription("Initializes a given command")
->setAliases(self::LEGACY_COMMANDS)
->addArgument(
"type",
InputArgument::REQUIRED,
InputArgument::OPTIONAL,
"The project type to initialize",
default: null,
suggestedValues: [
"symfony",
"library",
],
suggestedValues: self::ALLOWED_TYPES,
);
}

Expand All @@ -46,16 +53,26 @@ protected function execute (InputInterface $input, OutputInterface $output) : in
$io = new TorrStyle($input, $output);
$io->title("Janus: Initialize");

try
if (\in_array($input->getFirstArgument(), self::LEGACY_COMMANDS, true))
{
$io->caution("You are using a deprecated command. Use the `init` command instead.");
}

$type = $input->getArgument("type");

while (!\in_array($type, self::ALLOWED_TYPES, true))
{
$type = $input->getArgument("type");
\assert(\is_string($type));
$type = $io->choice("Please select the type to initialize", self::ALLOWED_TYPES);
}

\assert(\is_string($type));

try
{
$initializer = match ($type)
{
"symfony" => new SymfonyInitializer(),
"library" => new LibraryInitializer(),
default => null,
};

if (null === $initializer)

Check failure on line 78 in src/Command/InitializeCommand.php

View workflow job for this annotation

GitHub Actions / build-test (8.3)

Strict comparison using === between null and Janus\Initializer\LibraryInitializer|Janus\Initializer\SymfonyInitializer will always evaluate to false.
Expand Down

0 comments on commit c532e34

Please sign in to comment.