Migrate ListShortUrlsCommand to symfony/console attributes

This commit is contained in:
Alejandro Celaya
2025-12-13 11:05:20 +01:00
parent 89419e278c
commit a75ee138e1
6 changed files with 214 additions and 150 deletions

View File

@@ -12,6 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function is_string;
use function Shlinkio\Shlink\Core\normalizeOptionalDate;
use function sprintf;
readonly class DateOption
@@ -29,7 +30,7 @@ readonly class DateOption
}
try {
return Chronos::parse($value);
return normalizeOptionalDate($value);
} catch (Throwable $e) {
$output->writeln(sprintf(
'<comment>> Ignored provided "%s" since its value "%s" is not a valid date. <</comment>',

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Input;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function Shlinkio\Shlink\Core\normalizeOptionalDate;
use function sprintf;
final class InputUtils
{
/**
* Process a date provided via input params, and format it as ATOM.
* A warning is printed if the date cannot be parsed, returning `null` in that case.
*/
public static function processDate(string $name, string|null $value, OutputInterface $output): string|null
{
if ($value === null || $value === '') {
return null;
}
try {
return normalizeOptionalDate($value)->toAtomString();
} catch (Throwable) {
$output->writeln(sprintf(
'<comment>> Ignored provided "%s" since its value "%s" is not a valid date. <</comment>',
$name,
$value,
));
return null;
}
}
}