Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse command input parameter #1124

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leon0399
Copy link
Contributor

Q A
Bugfix?
Breaks BC?
New feature? ✔️
Issues N/A
Docs PR spiral/docs#...

ToDo

  • promptMissedArguments & getQuestion
  • Add Changelog
  • Add to docs

This feature is a logical continuation of https://spiral.dev/docs/cookbook-console-validation/current. If this PR is merged, it will now be allowed to configure attributes and options inside the Filter class without the need to duplicate fields and signature.

Currently, this PR is just a showcase of its features and implementation examples. I am willing to rework this PR as needed.

class UserRegisterFilter extends Filter
{
+    #[Argument(description: 'User username')]
    public string $username;

+    #[Argument(description: 'User email address')]
+    #[Question('Provide a valid email for the user')]
    public string $email;

+    #[Option(description: 'Mark as admin')]
    public bool $admin = false;

+    #[Option(key: 'send-verification-email', description: 'Send a verification email to the user')]
    public bool $sendVerificationEmail = false;
}

+#[AsCommand(user:register)]
final class UserRegister extends Command
{
-    protected const SIGNATURE = <<<CMD
-        user:register
-        {username : User username}
-        {email : User email address}
-        {--a|admin : Mark as admin}
-        {--s|send-verification-email : Send a verification email to the user}
-CMD;

-    public function perform(UserRegisterFilter $input): int
+    public function perform(#[AsInput] UserRegisterFilter $input): int
    {
        // ...

        return self::SUCCESS;
    }
}

@roxblnfk roxblnfk requested a review from a team August 25, 2024 07:21
@butschster butschster marked this pull request as ready for review September 2, 2024 10:52
@butschster
Copy link
Member

hey! Looks awesome. I like your idea to use Attributes for mapping input into a DTO. You can continue. I see some todo here.

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.

2 participants