-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
gii command #2789
gii command #2789
Conversation
I think it will be better to use console output to enable colors and not simple |
@Ragazzo Do you have any examples how to do that, the other core commands also use |
|
That's neat. I'm not quite sure what is the best syntax. How about splitting |
Thanks :) Here's another proposal: #1280 (comment) I was unsure about the parsing of the same param multiple times. Can |
@qiangxue Please see #1280 (comment) |
|
||
// TODO: is there are better way, needed for `./yii help gii` | ||
public function getUniqueId(){ | ||
return 'gii/'.$this->generatorName; |
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.
Why do you need to override this?
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.
$ ./yii help gii
DESCRIPTION
Allows you to run Gii from the command line.
Example command:
$ ./yii gii/<generator> --property1=foo --property2=bar --generate=true
SUB-COMMANDS
- gii/controllerPHP Fatal error: Call to a member function getUniqueId() on a non-object in /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/Action.php on line 69
PHP Stack trace:
PHP 1. {main}() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/yii:0
PHP 2. yii\base\Application->run() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/yii:23
PHP 3. yii\console\Application->handleRequest() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/Application.php:302
PHP 4. yii\console\Application->runAction() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/console/Application.php:140
PHP 5. yii\base\Module->runAction() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/console/Application.php:173
PHP 6. yii\console\Controller->runAction() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/Module.php:581
PHP 7. yii\base\Controller->runAction() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/console/Controller.php:83
PHP 8. yii\base\InlineAction->runWithParams() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/Controller.php:127
PHP 9. call_user_func_array:{/Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/InlineAction.php:54}() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/InlineAction.php:54
PHP 10. yii\console\controllers\HelpController->actionIndex() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/InlineAction.php:54
PHP 11. yii\console\controllers\HelpController->getControllerHelp() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/console/controllers/HelpController.php:66
PHP 12. yii\console\controllers\HelpController->getActionSummary() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/console/controllers/HelpController.php:222
PHP 13. yii\base\Action->getUniqueId() /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/console/controllers/HelpController.php:254
exception 'yii\base\ErrorException' with message 'Call to a member function getUniqueId() on a non-object' in /Users/tobias/hrzg/gitlab/phundament/app-local-v4/vendor/yiisoft/yii2-dev/framework/base/Action.php:69
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 needs some debugging. It means Action::controller
is null, which shouldn't happen normally.
@schmunk42 what's left in order for this cool feature to be merged? |
@samdark One problem at the moment is, that Yii 2 falsely detects module (web)-controllers as commands. So, in order to run the Gii command I had to configure Gii for the console as The other thing is the help section, see also #1280 (comment) But the functionality should be complete ... I'll review the code again in the next days. |
@schmunk42 Thanks. You may focus on the help section. I will look into the controller resolution issue. |
We should separate console and web controllers. they can not reside in the same dir. had the same problem when starting to implement this but had no time to finally handle it. |
…de the correct source class for generating the help texts
@qiangxue @cebe @samdark So, I got a "working" solution, but it needs some more refactoring. While I could still do this, I'd like to take a look at the current implementation (work in progress) where I just return the correct class to the help command for parsing the doc blocks. There are just some tiny changes to the help command instead of blowing up the base controller with code which is only needed for the help command. Maybe we could use an interface here to detect which controller/action has to be treated in a special way ... or we may add something like I'll also take care about moving the command to |
Current Status
Current Output
|
Overall it looks good. @cebe will you handle it? I can take it if you don't currently have enough time. |
I think the code about help documentation still needs to be reworked (as described in #1280 (comment)). The newly added methods in the base action class do not make sense for general actions. |
Just let me know, if I can still assist you with this (via github, Skype, etc...). |
I am going to look into this, just will take some more time. |
Conflicts: extensions/gii/Module.php
I've merged the latest master. This is my current console config, in
|
I was able to remove the 'gii-console' hack and the command it now works just by using bootstrapping gii on console, like you do it in backend. Regarding 607294a I still see 'gii' in the command list, when it is registered as a module in the console config; therefore the |
… into feature/gii-command
Could we please finish this one, I had to close #3273 because of too many changes. It would be a pity, if this one would also become unmergeable. |
will try to check it tomorrow. |
I moved this into an extension: https://github.com/dmstr/yii2-gii-command |
Draft
First off all I had a problem defining
gii
as a module for the console, it looks like the default controller is recognized as a command, so I had to configure the module asconsole-gii
temporarily.Sample output
The command works like this:
Custom generator:
Error output:
It can run the creation process and generate the files. Let me know what you think about the syntax.
If we can run commands from commands there's no need for a config file loader immediately.
I'll also try to implement the interactive fallback, if this approach is OK so far.