Skip to content
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

Add setProcessInput and deprecate setInput. #1034

Merged
merged 3 commits into from
May 20, 2021

Conversation

rodrigoaguilera
Copy link
Contributor

Overview

This pull request:

  • Fixes a bug
  • Adds a feature
  • Breaks backwards compatibility
  • Has tests that cover changes
  • Adds documentation

Summary

Use a different method name to set the input for a process as the current one is overridden by the InputAwareTrait used by the CollectionBuilder

Description

I was trying to provide a docker-compose.yml file via stdin by doing

$this
  ->taskExec('docker-compose')
  ->setInput($YamlFileContents)
  ->interactive(false)
  ->option('file', '/dev/stdin')
  ->arg('up')
  ->option('detach')
  ->run();

but the setInput() that ends up being called is not the one on the ExecTrait so I propose to deprecate setInput as it wasn't working anyway and add a new method name that is more descriptive.

I am not sure that interactive should also be set to false automatically when you provide input for the process but that can be a discussion for another issue.

@@ -21,6 +21,7 @@ if ($this->taskExec('phpunit .')->run()->wasSuccessful()) {

* `simulate($context)` {@inheritdoc}
* `setOutput($output)` Sets the Console Output.
* `setProcessInput($output)` Sets the input for the command. Similar to a pipe like `echo "input" | cat`. Usually followed by a call to `->interactive(false)` to avoid other inputs.
Copy link
Member

Choose a reason for hiding this comment

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

Typo, $output instead of $input.

@greg-1-anderson
Copy link
Member

I am not sure that interactive should also be set to false automatically when you provide input for the process but that can be a discussion for another issue.

This does not appear to be done, currently. Are you proposing that it should be? If there are no use cases where you need a tty with stdin redirection (seems reasonable to me), then the right time to make this behavior change would be now, when the new method name is introduced. The deprecated method should maintain the old behavior.

@rodrigoaguilera
Copy link
Contributor Author

Thanks for having a look.
It doesn't make sense to provide an input and have a tty allocated so yes, let's make that change. If there is a corner case when interactive is needed it can be set later. Also fixed the typo.

public function setInput($input)
{
trigger_error('setInput() is deprecated. Please use setProcessInput(().', E_USER_DEPRECATED);
return $this->setProcessInput($input);
Copy link
Member

Choose a reason for hiding this comment

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

setInput should maintain old behavior and not set interactive false

Copy link
Member

Choose a reason for hiding this comment

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

This is probably not necessary but I can't prove that it won't cause a problem for someone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But you are right, better keep the same behavior for the deprecated method.

@greg-1-anderson
Copy link
Member

Thanks!

@greg-1-anderson greg-1-anderson merged commit 85efe28 into consolidation:3.x May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants