-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2166 from acelaya-forks/feature/options-enum
Reduce hardcoded options in ShortUrlDataInput
- Loading branch information
Showing
2 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\CLI\Input; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
use function sprintf; | ||
|
||
enum ShortUrlDataOption: string | ||
{ | ||
case TAGS = 'tags'; | ||
case VALID_SINCE = 'valid-since'; | ||
case VALID_UNTIL = 'valid-until'; | ||
case MAX_VISITS = 'max-visits'; | ||
case TITLE = 'title'; | ||
case CRAWLABLE = 'crawlable'; | ||
case NO_FORWARD_QUERY = 'no-forward-query'; | ||
|
||
public function shortcut(): ?string | ||
{ | ||
return match ($this) { | ||
self::TAGS => 't', | ||
self::VALID_SINCE => 's', | ||
self::VALID_UNTIL => 'u', | ||
self::MAX_VISITS => 'm', | ||
self::TITLE => null, | ||
self::CRAWLABLE => 'r', | ||
self::NO_FORWARD_QUERY => 'w', | ||
}; | ||
} | ||
|
||
public function wasProvided(InputInterface $input): bool | ||
{ | ||
$option = sprintf('--%s', $this->value); | ||
$shortcut = $this->shortcut(); | ||
|
||
return $input->hasParameterOption($shortcut === null ? $option : [$option, sprintf('-%s', $shortcut)]); | ||
} | ||
} |