Skip to content

Conversation

@aazsamir
Copy link
Contributor

@aazsamir aazsamir commented Nov 13, 2024

This pull request brings possibility of using enums as command arguments.

So this will be possible

enum Type: string
{
    case JSON = 'json';
    case TEXT = 'text';
}

class MyCommand
{
    #[ConsoleCommand('cmd')]
    public function __invoke(Type $type): void {}
}

Call

./tempest cmd --type=json

in case of wrong value:

Invalid argument `invalid` for `type` argument, valid values are: json, text

And definition will be displayed as

cmd <type {json|text}>

@innocenzi innocenzi changed the title feat(console): accept \BackedEnum arguments for commands feat(console): accept BackedEnum as command arguments Nov 13, 2024
@aazsamir aazsamir marked this pull request as ready for review November 13, 2024 13:46
Copy link
Member

@innocenzi innocenzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome PR, I only have a few optional style nitpicks 👍

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11824085076

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 32 of 41 (78.05%) changed or added relevant lines in 4 files are covered.
  • 30 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.1%) to 82.602%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Tempest/Console/src/Exceptions/InvalidEnumArgument.php 2 11 18.18%
Files with Coverage Reduction New Missed Lines %
src/Tempest/Console/src/Highlight/TempestConsoleLanguage/TempestConsoleLanguage.php 4 78.95%
src/Tempest/Support/src/StringHelper.php 10 95.19%
src/Tempest/Support/src/ArrayHelper.php 16 94.59%
Totals Coverage Status
Change from base Build 11808519535: 0.1%
Covered Lines: 7435
Relevant Lines: 9001

💛 - Coveralls

@innocenzi innocenzi merged commit c21f24e into tempestphp:main Nov 13, 2024
56 checks passed
@innocenzi
Copy link
Member

Thanks!

@aazsamir aazsamir deleted the feat/console_enum_arguments branch November 13, 2024 22:10
Blurazzle pushed a commit to Blurazzle/tempest-framework that referenced this pull request Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants