ddev / ddev-contrib

Contrib space for DDEV services, tools, snippets, and approaches.
Apache License 2.0
162 stars 162 forks source link

Improve tinker command #200

Closed tyler36 closed 2 years ago

tyler36 commented 2 years ago

How this PR Solves The Problem:

Currently, there are issues with quotes and working with bash. There are some documented workaround in this command but they are not idea.

https://github.com/drud/ddev/pull/3603 opens up the possibility of support so this is kinda premptive and offers another real-world case for testing and support.

Ideally, we should be able to run the examples on the Drush php:eval page:

ddev tinker "$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();"
ddev tinker "node_access_rebuild()"

Manual Testing Instructions:

gitpod /workspace/d9simple (main) $ ddev tinker "dump(4+4)"
^ 8

Related Issue Link(s):

https://github.com/drud/ddev/pull/3603

rfay commented 2 years ago

Is this ready now with ddev v1.19?

tyler36 commented 2 years ago

There are issues with ( & ) but i suspect that relates back to https://github.com/drud/ddev/pull/3603

$ ddev tinker node_access_rebuild()
\bash: syntax error near unexpected token `('

$ ddev tinker 'node_access_rebuild()'
bash: -c: line 1: syntax error near unexpected token `('
bash: -c: line 1: `set -eu && ( /mnt/ddev_config/.global_commands/web/tinker node_access_rebuild())'

$ ddev tinker "node_access_rebuild()"
bash: -c: line 1: syntax error near unexpected token `('
bash: -c: line 1: `set -eu && ( /mnt/ddev_config/.global_commands/web/tinker node_access_rebuild())'

$ ddev tinker '"node_access_rebuild()"'
 [notice] Message: Content permissions have been rebuilt.

$ ddev tinker "'node_access_rebuild()'"
 [notice] Message: Content permissions have been rebuilt.

$ ddev tinker 'node_access_rebuild\(\)'
 [notice] Message: Content permissions have been rebuilt.

There are notes under the "laravel" section with examples.

This PR is still valid though since it still does add 2 features:

tyler36 commented 2 years ago

yes ... it's good to go.

tyler36 commented 2 years ago

Just been playing around with the command.

TLDR:

Window 10 Host

Laravel project

 ❯  ddev tinker 6+5
11

 ❯  ddev tinker User::find(1)
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.

   Psy\Exception\FatalErrorException

  PHP Fatal error:  Class constant 'User::find' not found in eval()'d code on line 1

  at :1
  ➜   1▕

 ❯  ddev tinker 'User::find(1)'
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
App\Models\User^ {#4271
...

 ❯  ddev tinker "User::find(1)"
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
App\Models\User^ {#4271
...

Drupal 9 project

 ❯  ddev tinker 'node_access_rebuild()'
 [notice] Message: Content permissions have been rebuilt.

 ❯ ddev tinker "$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();"
 [error]  ParseError: syntax error, unexpected token "=", expecting end of file in Drush\Commands\core\PhpCommands->evaluate() (line 1 of /var/www/html/vendor/drush/drush/src/Commands/core/PhpCommands.php(30) : eval()'d code) #0 [internal function]: Drush\Commands\core\PhpCommands->evaluate(' = \\Drupal\\node...', Array)

 ❯ ddev tinker '$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();'
Who Doesn’t Like a Good Waterfall?

WSL Ubuntu

Laravel project

$ ddev tinker 6+5
11

$ ddev tinker User::find(1)
-bash: syntax error near unexpected token `('

$ ddev tinker 'User::find(1)'
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
App\Models\User^ {#4647
...

$ ddev tinker "User::find(1)"
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
App\Models\User^ {#4647
...

Drupal 9 project

$ ddev tinker 'node_access_rebuild()'
 [notice] Message: Content permissions have been rebuilt.

$ ddev tinker "node_access_rebuild()"
 [notice] Message: Content permissions have been rebuilt.

$ ddev tinker "$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();"
 [error]  ParseError: syntax error, unexpected token "=", expecting end of file in Drush\Commands\core\PhpCommands->evaluate() (line 1 of /var/www/html/vendor/drush/drush/src/Commands/core/PhpCommands.php(30)

$ ddev tinker '$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();'
Who Doesn’t Like a Good Waterfall? 
rfay commented 2 years ago

When you do ddev tinker "$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();" bash is turning \D into a control character before ever using it...

rfay commented 2 years ago

If you're happy with it i'll pull it.

tyler36 commented 2 years ago

I am happy with it. The readme has example of usage and it is an improvement over the current version. Thank you.