framework
framework copied to clipboard
Parse command input parameter
| 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;
}
}
hey! Looks awesome. I like your idea to use Attributes for mapping input into a DTO. You can continue. I see some todo here.