Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Support backed enums for invokable command as argument and option #60433

Open
Labels
ConsoleRFCRFC = Request For Comments (proposals about features that you want to be discussed)
@GromNaN

Description

@GromNaN

Description

Enums represent aclosed list of possible values. Supportingbacked enums as option or argument type would enable:

  • Auto-completion from enum cases values (ie:suggestedValues: BackedEnum::cases() values)
  • Validation of the input value with a nice error message
  • No need to callBackedEnum::tryFrom($input) in the command__invoke.

In Symfony itself, most of the--format options could be enums.

Example

Given a backed enum like this:

enum EmbeddingType:string{case Image ='image';case Description ='description';}

The argument parameter should accept a backed enum type,

#[AsCommand(name:'app:regenerate')]class RegenerateCommand{publicfunction__invoke(#[Argument]EmbeddingType$type):int    {$this->generator->generate($type);    }}

If the command is run with an invalid value, an error is returned.

$ app/console app:regenerate yolo                                         The "yolo" value is not accepted. Use one of "image", "description".

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConsoleRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp