Parse command input parameter #1124
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ToDo
promptMissedArguments&getQuestionThis 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; } }