Skip to content

Commit

Permalink
Improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed Jun 4, 2024
1 parent 23030f1 commit 3962817
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/Command/InitializeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function execute (InputInterface $input, OutputInterface $output) : in
}

$type = $input->getArgument("type");
\assert(null === $type || \is_string($type));

if (!\in_array($type, self::ALLOWED_TYPES, true))
{
Expand All @@ -74,33 +75,16 @@ protected function execute (InputInterface $input, OutputInterface $output) : in

try
{
$initializer = match ($type)
return match ($type)
{
"symfony" => new SymfonyInitializer(),
"library" => new LibraryInitializer(),
"symfony" => (new SymfonyInitializer())->initialize($io),
"library" => (new LibraryInitializer())->initialize($io),
};

if (null === $initializer)
{
return $this->printError($io, $type);
}

return $initializer->initialize($io);
}
catch (\Throwable $exception)
{
$io->error("Running janus failed: {$exception->getMessage()}");
return 2;
}
}

/**
* Prints an error
*/
private function printError (TorrStyle $io, string $type) : int
{
$io->error("Unknown type: {$type}");

return self::FAILURE;
}
}

0 comments on commit 3962817

Please sign in to comment.