-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Fix passing options with defaultCommand #22244
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
[Console] Fix passing options with defaultCommand #22244
Conversation
6a6565d
to
00b1d79
Compare
ping @lyrixx? |
I don't know. But without test, It can not be merged. |
It never worked (tried 2.7.0 out).
|
I'll create a unit test for that use case later today. Could someone give me a hand with that "interact called" thing in the unit tests, that is failing? @chalasr it can only work with options. The first argument is used as a command name, so it's never a case.
|
@@ -179,7 +179,9 @@ public function doRun(InputInterface $input, OutputInterface $output) | ||
|
||
if (!$name) { | ||
$name = $this->defaultCommand; | ||
$input = new ArrayInput(array('command' => $this->defaultCommand)); | ||
$inputArgument = $this->definition->getArgument('command'); | ||
$inputArgument->setMode(InputArgument::OPTIONAL); |
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.
this is kind of ugly fix, that allows me to call setDefault() - it disallows setting a default value for the commands with REQUIRED value.
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.
We could get rid of the setter by redefining the argument entirely e.g
- $inputArgument = $this->definition->getArgument('command');
- $inputArgument->setMode(InputArgument::OPTIONAL);
- $inputArgument->setDefault($name);
+ $this->definition->setArguments(array_merge(
+ $this->definition->getArguments(),
+ array('command' => new InputArgument('command', InputArgument::OPTIONAL, this->definition->getArgument('command')->getDescription(), $name))
+ ));
(not tested)
6db5e8d
to
065f3d5
Compare
ok seems much better to me now. I added test as well. I still have no clue why travis fails with:
Can anyone help me with that? |
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.
👍 with minor comment
InputArgument::OPTIONAL, | ||
$this->definition->getArgument('command')->getDescription(), | ||
$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.
I would put the whole array on 1 line.
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.
as requested.
065f3d5
to
259de3c
Compare
@chalasr is there anything else for me to do here? especially with that failing unit test. |
@jakubsacha I given a quick look at the build failure 2 days ago trying to reproduce, unfortunately I don't know what happen either, the test runs fine locally. I would suggest to rebase this PR against the current master since there is a lot of activity on it these days. I will give a deeper look into the failing test. Apart from that, this looks good to me. |
'fo', | ||
InputOption::VALUE_OPTIONAL, | ||
'fooopt description' | ||
) |
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.
This should be on one line as well
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.
fixed.
So, we would allow options to work but not arguments, right? |
Arguments work already, but the first needs to be the command name (we could not guess it from the default command as we can't predict which value targets which argument in the raw input token). Actually you can't do:
You have to specify the command name to have options taken into account. This PR proposes to allow omitting it so that |
@fabpot correct. In case you have arguments the first one becomes command name, and you don't have that issue. The problem is only for defaultCommand. |
9975d8e
to
94ca088
Compare
@jakubsacha this statement is reached in the build, thus |
c861433
to
5977146
Compare
5977146
to
761de99
Compare
Ok I think I understand what was the problem: Current Symfony 2.7 behaviour:
Unit tests were failing because I didn't create new Input but used one passed initially. Since my input is processed by configureIO and the shell is not interactive in the CI systems, it failed. I forced non-interactive execution of the tests, but I'm not sure is it the best approach. |
ping @chalasr |
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.
👍 from my side
@fabpot kind ping again;-) any chance we get it through? |
@fabpot @Simperfit @chalasr @lyrixx it's been some time. It's still relevant to me. Can we merge it? |
ping @ogizanagi also :) |
Just checked this out again. The changes in ApplicationTest might look suspicious, but this fix just reveals that the fact we are currently creating a new ArrayInput instance makes |
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.
LGTM 👍
Thank you @jakubsacha. |
…acha) This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix passing options with defaultCommand | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Seems like overwriting input for the default command is not needed (anymore?). I don't know where the removed comment comes from originally. Use case: i want to call default command and use options at the same time: app/console --abc=true Commits ------- 761de99 Fix passing options with defaultCommand
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
* Yaml::parseFile() wasn't present untill 3.4 > use parse() with file_get_contents() * Process didn't accept array untill 3.3 > Update to 3.3+ as 4.0+ needs array * Console had a bug issue in with empty defaults prior to 3.3.^ & 3.2.13 See: symfony/symfony#22244 > Update minimum to 3.13 and add a conflict rune for between 3.3.0 and 3.3.5 Be sure to test against lowest versions on travis.
Seems like overwriting input for the default command is not needed (anymore?). I don't know where the removed comment comes from originally.
Use case: i want to call default command and use options at the same time:
app/console --abc=true