netz98 / n98-magerun2

The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.
https://magerun.net
Other
872 stars 225 forks source link

make:... commands to create all kinds of things #833

Closed kolaente closed 6 months ago

kolaente commented 3 years ago

Feature description

I would love to have an n98-magerun2 make:... command, like there exists for Laravel (php artisan make:controller for example).

For example, running something like n98-magerun2 make:data-patch <module> <name> would create an empty class <name> in <module>/Setup/Patch/Data that implements \Magento\Framework\Setup\Patch\DataPatchInterface and has the base methods of the interface already created. This could be extended to tests, models, repositories, etc.

Problem and motivation

I found myself creating a few data patches lately and manually creating the classes feels like there should be a better way.

Is this something you're interested in working on

If I get time to work on it, yes :slightly_smiling_face: @amenk

amenk commented 3 years ago

https://github.com/netz98/n98-magerun2/wiki/Interactive-Console-%28REPL%29#code-generator :-)

kolaente commented 3 years ago

https://github.com/netz98/n98-magerun2/wiki/Interactive-Console-%28REPL%29#code-generator :-)

Okay I did not know that was a thing :upside_down_face: I guess this Feature request then extends to a) making the code generation commands available as a sub command of magerun (without calling the REPL first) and then adding a new command to create data patches.

amenk commented 3 years ago

..or first add the data patch command and decide later whether to make it available outside of the REPL :)

amenk commented 3 years ago

@cmuench Is there a specific reason to have this commands only in the REPL and not directly-callable?

cmuench commented 3 years ago

@amenk the dev:console is inspired by the tool "Installer" by Jacques Bodin-Hullin. That's how it is designed. It's not designed for scripting. So.... historic. It's possible to add new commands to the REPL as, well. Commands are registered here: https://github.com/netz98/n98-magerun2/blob/develop/config.yaml#L445 I have not tried to call them in a different contect. Maybe it could be possible to add a kind of proxy command here. Something like dev:console:call <command> ....

amenk commented 3 years ago
 n98-magerun2.phar dev:console "$a = 1; call cache:flush; ls;"

seems already possible anyways...

I would also recommend to focus on adding new generators instead of doing such general changes like adding the Laravel artisan mode :-)

cmuench commented 3 years ago

@amenk Could be that I already worked on that topic (I am getting old...), but I guess it's unstable.

kolaente commented 3 years ago

seems already possible anyways...

This seems to work with a bash function:

$ m() { n98-magerun2 dev:console "call $1;exit"; }
$ m cache:flush                              
Magento 2.4.2 Community initialized ✔
At the prompt, type help for some help.

To exit the shell, type ^D.
Psy Shell v0.9.12 (PHP 7.4.23 — cli) by Justin Hileman
New version is available (current: v0.9.12, latest: v0.10.8)
-->  call cache:flush
.....

That pretty much gets me the "laravel feeling".

So yeah, I'll put up a PR to add a new data patch generator I guess.

cmuench commented 3 years ago

@kolaente Feel free to extend the dev:console.

amenk commented 1 year ago

We saw that https://plugins.jetbrains.com/plugin/8024-magento-phpstorm has such a function and will probably not extend that further here in Magerun2, issue can eventually be closed :-)

image

cmuench commented 1 year ago

We saw that https://plugins.jetbrains.com/plugin/8024-magento-phpstorm has such a function and will probably not extend that further here in Magerun2, issue can eventually be closed :-)

image

The dev console can be triggered from outside. So it's possible to use the feature for scripting, too. That's IMHO not possible with the PhpStorm Plugin. So there is a place for both.

amenk commented 1 year ago

The dev:console is awesome :-) I am more talking about such code generation features, those I feel to be more natural in PhpStorm - at least for us :-)

cmuench commented 1 year ago

The dev:console is awesome :-) I am more talking about such code generation features, those I feel to be more natural in PhpStorm - at least for us :-)

That's ok for me if you use PhpStorm. ;-)

cmuench commented 6 months ago

I close this ticket. We should add more specific issues to enhance the dev:console. Feel free to create new issue here.