-
Notifications
You must be signed in to change notification settings - Fork 314
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
Better plumbing. #622
Better plumbing. #622
Conversation
test/ShellTest.php
Outdated
@@ -384,6 +384,8 @@ public function testWriteStdout() | |||
|
|||
public function testWriteStdoutWithoutNewline() | |||
{ | |||
$this->markTestSkipped('This test won\'t work on CI without overriding pipe detection'); |
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 test is always skipped, even not on the CI?
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.
It'll fail locally if you pipe your phpunit output, too :)
I didn't really want a mock or an override or anything for the piped output detection, but I think I'm going to need it.
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.
It feels like there might be one more configuration option missing. Some way to say "force this to act like output isn't piped", just like we have "force this to decorate output" and "force this to act like input is interactive".
I haven't decided yet whether that's exactly the same as "force this to decorate output", but it might be.
Codecov Report
@@ Coverage Diff @@
## master #622 +/- ##
============================================
+ Coverage 67.06% 67.28% +0.22%
============================================
Files 129 127 -2
Lines 5207 5126 -81
============================================
- Hits 3492 3449 -43
+ Misses 1715 1677 -38
Continue to review full report at Codecov.
|
src/Shell.php
Outdated
$this->writeVersionInfo(); | ||
$this->writeStartupMessage(); | ||
// Show a startup message, as long as output isn't piped. | ||
if (!$this->config->outputIsPiped()) { |
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.
After playing with it a bit, this isn't right. A forced interactive run should have a header, just like an implicitly interactive run. Pushing a fix for this.
This all feels pretty good, with the exception of the cli option names. I feel like
In addition to those, there are a bunch of aliases; |
bd1df40
to
f1320f0
Compare
- Default to non-interactive when input is piped.
f1320f0
to
eb16fff
Compare
src/Configuration.php
Outdated
$config = new self(['configFile' => $input->getOption('config')]); | ||
|
||
// Handle --color and --no-color (and --ansi and --no-ansi aliases) | ||
if ($input->getOption('color') || $input->getOption('ansi')) { |
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'm feeling really good about this pull request. I think this is my last open question:
Should we use InputInterface::getOption
?
Using getOption
like we are here means things will blow up if we're handed input that hasn't been bound to a compatible input options definition. It is more correct, though. We just can't really enforce that people give us good input.
The more pragmatic approach is probably to use the underlying hasParameterOption
/ getParameterOption
and do some more of the parsing and interpreting work manually, ourselves. It's not as clean, and not as guaranteed-correct, but it also doesn't rely on callers having already bound compatible options.
Either way, we'd still continue binding the input properly in bin/psysh
when we call it. We'd just be more forgiving of other callers not doing the same.
I'm leaning towards the second option.
@GrahamCampbell what do you think? This is somewhat relevant to laravel/tinker#98 🙂
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.
K. I wen't with a third option.
I've got something that works either way, though definitely better with bound input. See 3c9b112.
It's a bit of a mess, but probably acceptably tucked away from end users that it won't be an issue?
4a5066b
to
fc6cb55
Compare
- Move responsibility for command line option declarations into `Configuration::getInputOptions`. - Move responsibility for overriding configuration via command line options into `Configuration::fromInput`. - Remove an implicit dependency on side effects from command line option name collisions with the base Console Application (this made `--verbose`, `--no-interaction`, and `--ansi` ... kind of work). Update available command-line options: - `--interactive` and `--no-interactive` for interactive mode input. - `--color` and `--no-color` for decorated output. - `--verbose`, `--quiet` and `-v`/`-vv`/`-vvv` for output verbosity. Add option aliases for compatibility with Symfony, Composer, and other familiar tools: - `--ansi` and `--no-ansi` for `--color` and `--no-color`. - `--no-interaction` for `--no-interactive`. - `-i` and `-a` to force interactive mode input (hey there `php -a`).
fc6cb55
to
72d5db9
Compare
This removes an implicit dependency on side effects from command line options, which was caused by name collisions with the base Console Application.
Things like
--verbose
and--no-interaction
worked ... kind of. But not always (see #621, for example). And when it did work, it's only because both PsySH and the base Applcation were parsing argv and reading the options passed.Improved plumbing, specifically:
Improved output:
--raw
or piping stdout.New configuration:
psy\info()
output.Improved configuration:
Configuration::fromInput
Configuration::getInputOptions
Drive by:
--ansi
and--no-ansi
aliases for color cli options (to match Symfony console and Composer).