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

Support cli.php -c value command -o option #16

Closed
wants to merge 1 commit into from

Conversation

rubensayshi
Copy link

I'd like to be able to add InputOptions with with VALUE_REQUIRED to the Application::getDefaultInputDefinition because for some things it's just more natural for options to precede the command (eg; cli.php --config ~/.mycnf do_something --another option.

However the code relies on the token being the first argument (being the command) and does not take the InputDefinition into consideration for this.

I'm not entirely sure if this is the right way to solve it, I don't know if the Application::run just takes the 2 arguments for testing purposes or if there are other reasons, when I needed to do $application->getDefinition() in the tests I realised that if someone would feed Application::run a custom Input they'd have to do that too, which might be odd?

…t should not use it's value as the first argument
@rubensayshi
Copy link
Author

never, this PR seems to break the arguments after it

@rubensayshi
Copy link
Author

@fabpot any ideas on how I could get this behavory?

symfony-splitter pushed a commit that referenced this pull request Sep 28, 2024
…adFromProcess` (fritzmg)

This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Suppress `proc_open` errors within `Terminal::readFromProcess`

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

When instantiating `SymfonyStyle` in a command it will try to determine the maximum width of the current console interface.

https://github.com/symfony/symfony/blob/6687e4ea35f45ebd73fb0315938103628cfb13a0/src/Symfony/Component/Console/Style/SymfonyStyle.php#L53

This will execute `stty -a | grep columns` down the line. Access to `stty` might be disallowed however, resulting in the following error:

```
ErrorException: Warning: proc_open(): Exec failed: Permission denied
#16 /vendor/symfony/console/Terminal.php(220): Symfony\Component\Console\Terminal::readFromProcess
#15 /vendor/symfony/console/Terminal.php(204): Symfony\Component\Console\Terminal::getSttyColumns
#14 /vendor/symfony/console/Terminal.php(170): Symfony\Component\Console\Terminal::initDimensionsUsingStty
#13 /vendor/symfony/console/Terminal.php(153): Symfony\Component\Console\Terminal::initDimensions
#12 /vendor/symfony/console/Terminal.php(94): Symfony\Component\Console\Terminal::getWidth
#11 /vendor/symfony/console/Style/SymfonyStyle.php(55): Symfony\Component\Console\Style\SymfonyStyle::__construct
#10 /vendor/symfony/messenger/Command/ConsumeMessagesCommand.php(136): Symfony\Component\Messenger\Command\ConsumeMessagesCommand::interact
#9 /vendor/symfony/console/Command/Command.php(311): Symfony\Component\Console\Command\Command::run
```

(Stack Trace actually from Symfony 6)

The phpDoc of `Terminal::getSttyColumns` states

> Runs and parses stty -a if it's available, _suppressing any error output_.

The latter might refer to `['suppress_errors' => true]` (though I am not sure) - which is a Windows only functionality. In any case, since `Terminal::readFromProcess` already checks for

```php
if (!$process = proc_open(…)) {
    return null;
}
```

and

```php
if (!\is_resource($process)) {
    return null;
}
```

upstream in Symfony 6/7, indicating that `proc_open` might fail - this error can additionally be suppressed using `@`. Besides, `Process::start` also uses ``@proc_open`` (added in symfony/symfony@099481f "Prevent warning in proc_open()").

Commits
-------

575249a3431 suppress proc_open errors
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.

1 participant