drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

Support psysh 'requireSemicolons' in php:cli #5160

Closed andriokha closed 2 years ago

andriokha commented 2 years ago

Is your feature request related to a problem? Please describe. By default psysh does a kind of JS-like automatic semicolon insertion for convenience, automatically adding one after each line break. And a lot of time it's convenient. But I'm always frustrated when I have a bit of multiline code that I want to test in the REPL, and instead of just copying and pasting, I have to reformat it onto one line.

Describe the solution you'd like Psysh has an option that requires semicolons: requireSemicolons. I've tested it locally and it works as advertised. I suggest supporting that. I'm not sure if it makes more sense to have a dedicated option, or a general mechanism to pass psysh config options through (insert obligatory xkcd reference!).

Thanks for this life-saving tool :heart:

andriokha commented 2 years ago

Thought a possible alternative might be to change it dynamically from within the REPL itself, but it looks like that's not possible at the mo: https://github.com/bobthecow/psysh/issues/361

andriokha commented 2 years ago

Ah, I can use a psysh config file without any change to drush. In combination with the PSYSH_CONFIG env var I can use something like

PSYSH_CONFIG=config-multiline.php drush php

I'll leave the request open because it's not super convenient, see what others think (:

Thanks!

andriokha commented 2 years ago

K, I'm going to close this. If you'd like to be able to copy and paste a single logical line that's spread over multiple actual lines in drush core:cli you can use the following.

  1. Put this in some PHP file:
    <?php
    return [
     'requireSemicolons' => TRUE,
    ];
  2. Run the following:
    PSYSH_CONFIG=path/to/file/from/docroot/file.php drush php
  3. You should be able to paste eg. the following and it will work (note the required semicolon):
    \Drupal::entityTypeManager()
     ->getStorage('node')
     ->getQuery()
     ->count()
     ->accessCheck(FALSE)
     ->execute();

Thanks!

bobthecow commented 1 year ago

You should also be able to add a .psysh.php file with that config to your project directory and it'll do this by default!