Skip to content

Commit

Permalink
Use options instead of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Dec 17, 2023
1 parent 96f244f commit ed46700
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/Command/GenerateManifestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
Expand Down Expand Up @@ -47,10 +47,16 @@ public function __construct(

protected function configure(): void
{
$this->addArgument('url_prefix', InputArgument::OPTIONAL, 'Public URL prefix', '');
$this->addArgument('public_folder', InputArgument::OPTIONAL, 'Public folder', $this->rootDir . '/public');
$this->addArgument('asset_folder', InputArgument::OPTIONAL, 'Asset folder', '/pwa');
$this->addArgument('output', InputArgument::OPTIONAL, 'Output file', 'pwa.json');
$this->addOption('url_prefix', 'u', InputOption::VALUE_OPTIONAL, 'Public URL prefix', '');
$this->addOption(
'public_folder',
'p',
InputOption::VALUE_OPTIONAL,
'Public folder',
$this->rootDir . '/public'
);
$this->addOption('asset_folder', 'a', InputOption::VALUE_OPTIONAL, 'Asset folder', '/pwa');
$this->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Output file', 'pwa.json');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -60,10 +66,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$manifest = $this->config;
$manifest = array_filter($manifest, static fn ($value) => ($value !== null && $value !== []));

$publicUrl = $input->getArgument('url_prefix');
$publicFolder = Path::canonicalize($input->getArgument('public_folder'));
$assetFolder = '/' . trim((string) $input->getArgument('asset_folder'), '/');
$outputFile = '/' . trim((string) $input->getArgument('output'), '/');
$publicUrl = $input->getOption('url_prefix');
$publicFolder = Path::canonicalize($input->getOption('public_folder'));
$assetFolder = '/' . trim((string) $input->getOption('asset_folder'), '/');
$outputFile = '/' . trim((string) $input->getOption('output'), '/');

if (! $this->filesystem->exists($publicFolder)) {
$this->filesystem->mkdir($publicFolder);
Expand Down
5 changes: 4 additions & 1 deletion tests/Functional/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public static function theCommandCanGenerateTheManifestAndIcons(): void

// When
$commandTester->execute([
'public_folder' => sprintf('%s/samples', $kernel->getCacheDir()),
'--url_prefix' => '/foo/bar',
'--public_folder' => sprintf('%s/samples', $kernel->getCacheDir()),
'--asset_folder' => '/data',
'--output' => 'my-pwa.json',
]);

// Then
Expand Down

0 comments on commit ed46700

Please sign in to comment.