Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Merged
merged 1 commit into from
Jul 29, 2017

Conversation

jakubsacha
Copy link
Contributor

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

@jakubsacha jakubsacha changed the title Fix passing options with defaultCommand [Console] Fix passing options with defaultCommand Apr 2, 2017
@jakubsacha jakubsacha force-pushed the default-command-options-arguments branch 5 times, most recently from 6a6565d to 00b1d79 Compare April 3, 2017 05:31
@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Apr 3, 2017
@nicolas-grekas
Copy link
Member

ping @lyrixx?

@lyrixx
Copy link
Member

lyrixx commented Apr 3, 2017

I don't know. But without test, It can not be merged.

@chalasr
Copy link
Member

chalasr commented Apr 3, 2017

It never worked (tried 2.7.0 out).

Also what about arguments? Here, the first passed argument will just be considered as the command name. Just wondering if we should expect the command argument value to be automatically set instead? It would echo the behavior of single command applications since 3.2, which sounds good to me (as a feature on master). It can't work.

@jakubsacha
Copy link
Contributor Author

jakubsacha commented Apr 3, 2017

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.

app/console --abc=true this invocation should call default command and pass abc as an option. This is the only use case i can think about at the moment.

@@ -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);
Copy link
Contributor Author

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.

Copy link
Member

@chalasr chalasr Apr 3, 2017

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)

@jakubsacha jakubsacha force-pushed the default-command-options-arguments branch from 6db5e8d to 065f3d5 Compare April 3, 2017 15:51
@jakubsacha
Copy link
Contributor Author

ok seems much better to me now. I added test as well. I still have no clue why travis fails with:

2) Symfony\Component\Console\Tests\ApplicationTest::testSetRunCustomDefaultCommandWithOption
Application runs the default set command if different from 'list' command
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'interact called
-called
+'called
 opt
 '

Can anyone help me with that?

Copy link
Member

@chalasr chalasr left a 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),
)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as requested.

@jakubsacha jakubsacha force-pushed the default-command-options-arguments branch from 065f3d5 to 259de3c Compare April 3, 2017 16:43
@jakubsacha
Copy link
Contributor Author

@chalasr is there anything else for me to do here? especially with that failing unit test.

@chalasr
Copy link
Member

chalasr commented Apr 5, 2017

@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'
)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@fabpot
Copy link
Member

fabpot commented Apr 5, 2017

So, we would allow options to work but not arguments, right?

@chalasr
Copy link
Member

chalasr commented Apr 5, 2017

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:

php console.php --foo=bar // default command executed,  getOption('foo') is NULL

You have to specify the command name to have options taken into account. This PR proposes to allow omitting it so that getOption('foo') is equal to bar using the previous example

@jakubsacha
Copy link
Contributor Author

@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.

@jakubsacha jakubsacha force-pushed the default-command-options-arguments branch from 9975d8e to 94ca088 Compare April 6, 2017 06:48
@chalasr
Copy link
Member

chalasr commented Apr 6, 2017

@jakubsacha this statement is reached in the build, thus interact() is not called. Dunno why it happens in your PR and not in the current 2.7 build.

@jakubsacha jakubsacha force-pushed the default-command-options-arguments branch from c861433 to 5977146 Compare April 7, 2017 21:47
@jakubsacha jakubsacha force-pushed the default-command-options-arguments branch from 5977146 to 761de99 Compare April 7, 2017 21:55
@jakubsacha
Copy link
Contributor Author

Ok I think I understand what was the problem:

Current Symfony 2.7 behaviour:

  • ArrayInput is created in the ApplicationTester
  • It's passed through Application::run to Application::configureIO, where interactive shell is disabled
  • ArrayInput is recreated in Application::doRun, and by default interactive shell is true. and its done after configureIO is called.

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.

@jakubsacha
Copy link
Contributor Author

ping @chalasr

@jakubsacha
Copy link
Contributor Author

ping @chalasr @fabpot. could we do anything with that pull request? i think it's ready to merge.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from my side

@jakubsacha
Copy link
Contributor Author

@fabpot kind ping again;-) any chance we get it through?

@jakubsacha
Copy link
Contributor Author

@fabpot @Simperfit @chalasr @lyrixx it's been some time. It's still relevant to me. Can we merge it?

@nicolas-grekas
Copy link
Member

ping @ogizanagi also :)

@chalasr
Copy link
Member

chalasr commented Jul 28, 2017

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 interactive to true in the middle of a command execution even if not a tty.
This fixes a real bug: input options and arguments are lost when the default command is used.
Still 👍 for me.

Copy link
Contributor

@ogizanagi ogizanagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@fabpot
Copy link
Member

fabpot commented Jul 29, 2017

Thank you @jakubsacha.

@fabpot fabpot merged commit 761de99 into symfony:2.7 Jul 29, 2017
fabpot added a commit that referenced this pull request Jul 29, 2017
…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
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Aug 11, 2018
* 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.
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Aug 11, 2018
* 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.
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Aug 19, 2018
* 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.
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Sep 13, 2018
* 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.
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Sep 26, 2018
* 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.
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Oct 22, 2018
* 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.
BackEndTea added a commit to BackEndTea/infection that referenced this pull request Nov 7, 2018
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.