mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Migrate ListShortUrlsCommand to symfony/console attributes
This commit is contained in:
@@ -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>',
|
||||
|
||||
37
module/CLI/src/Input/InputUtils.php
Normal file
37
module/CLI/src/Input/InputUtils.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user