Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Console] Invokable command adjustments#59493
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Still analyzing the last two#59340 (comment)#59340 (comment) |
6094cd1
to730d374
Compareyceruto commentedJan 13, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Update after latest changes:
I added more tests to cover those scenarios. |
I've a question about non-boolean options: when defined without a default, e.g. |
This makes sense to me. Most important thing is a clear error message. |
I was expecting this topic to arise, not trivial :) I wouldn't be happy with invokable commands not supporting |
730d374
tod740cfa
CompareLet's lay out all the scenarios on the table so everyone can see the alternatives and how to implement them effectively with this new invokable approach. We can use input options in three different ways: If a default value is defined, it will be used as the option's value only in case (C). In case (B), the option value will be That's how regular commands work currently. Input options are optional by nature. This means the parameter must either:
However, input options can never be mandatory. This means defining them like The specific mode |
yceruto commentedJan 14, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've updated the code based on this analysis (it's pending throwing an exception for mandatory option parameters) |
kbond commentedJan 14, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think the only mode I don't support here:https://github.com/zenstruck/console-extra?tab=readme-ov-file#invokable-attributes is |
Requiring |
Uh oh!
There was an error while loading.Please reload this page.
d740cfa
to4e96f0a
Compareyceruto commentedJan 15, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
would making it nullable be sufficient? That's the approach used here, so you can declare an option with an optional value as But to be honest, I don’t know for which use case it makes sense, because the intention of passing such an option without a value feels more like a boolean option instead. |
To distinguish between an option passed without a value and not passed at all, set a default value: |
@@ -164,9 +168,6 @@ public function isEnabled(): bool | |||
*/ | |||
protectedfunctionconfigure() | |||
{ | |||
if (!$this->code &&\is_callable($this)) { | |||
$this->code =newInvokableCommand($this,$this(...)); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Moved to the constructor to allow overriding theconfigure()
method without requiring a call to the parent implementation
} | ||
}else { | ||
$code =$code(...); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Moved toInvokableCommand
which supports handling static anonymous functions too
The case of I agree about adding the negatable flag only for boolean options that don't have |
That makes sense to me@stof. PR updated! Not entirely sure about the flag though, let’s see what others think |
@@ -99,6 +99,6 @@ public function toInputArgument(): InputArgument | |||
*/ | |||
public function resolveValue(InputInterface $input): mixed | |||
{ | |||
return $input->hasArgument($this->name) ? $input->getArgument($this->name) : null; | |||
return $input->getArgument($this->name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
removed$input->hasArgument($this->name)
as it's better to get the "argument does not exist" exception than a TypeError or just null (if nullable)
After a deep analysis with Kevin, we decided to simplify the argument/option definition by removing the |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Yea it requires checking both
It's true there are certainly plenty of misuses, yet there are lots of usages and some are valid. Looking only at public github repos:https://github.com/search?q=InputOption%3A%3AVALUE_OPTIONAL&type=code. |
@chalasr after this pr is merged I'm going to open one dedicated to |
476b881
toe3c2c0d
Comparee3c2c0d
to8ab2f32
CompareThank you@yceruto. |
b684e7e
intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
Adjustments based on the latest reviews from#59340