yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

Gii with --generate=1 is not available in cli and does not overwrite existing files as is claimed in the phpdoc #5610

Closed motin closed 10 years ago

motin commented 10 years ago

Phpdoc claim: https://github.com/yiisoft/yii2/blob/7324f21dca2792f343ad1ad86122d123f3767616/extensions/gii/console/GenerateController.php#L35-L37

In reality, running any gii command in cli with --generate=1 results in:

 Error: Unknown option: --generate

When support for this option is added to cli, the option is ignored and gii will ask for confirmation before overwriting files, despite using --interactive=0.

Suggested solution:

  1. Add support for --generate option
  2. Overwrite changed files automatically when --interactive=0 and --generate=1
  3. Ignore the value of the --generate option when --interactive=1

A PR is on it's way.

qiangxue commented 10 years ago

Removed generate since it overlaps with interactive and would cause confusion. It was there because the original code was copied from previous PR.

motin commented 10 years ago

@qiangxue: What is a more appropriate option name? --overwrite=y like in ./init? --overwrite=1 so that it stays a boolean? (Overwriting files on --interactive=0 seems a bit dangerous.)

qiangxue commented 10 years ago

I think we can leave it as is unless there are more requests for change of the behavior. It depends on in which case you would use --interactive=0.

motin commented 10 years ago

Currently gii cli can't overwrite files in non-interactive mode. This makes it cumbersome to re-generate models and crud in an automated or scripted manner. Using --interactive=0 today is more like a --dry-run=1 option, since it shows changes but does not overwrite anything. Should we make --interactive=0 overwrite files by default and add a --dry-run option instead for the current behavior?

schmunk42 commented 10 years ago

Wll there be another possibility to regenerate all files?

I think this line: https://github.com/yiisoft/yii2/blob/master/extensions/gii/console/GenerateAction.php#L59

should read:

$skipAll = $this->controller->interactive ? null : false;

Which would regenerate all files if running in non-interactive mode.

motin commented 10 years ago

@schmunk42: Yes, that would make --interactive=0 overwrite files by default. Even better than having a separate confusing --generate option. Personally I don't need the --dry-run options, since it is easy to revert all changes files using git.

schmunk42 commented 10 years ago

@qiangxue In which case do you need this? continued

For generating a batch of models and CRUDs during very early development. It's very cumbersome to manually use y or ya when there are a lot of changes in many models. But this applies for all Gii actions which may overwrite a large number of files.

qiangxue commented 10 years ago

Fixed. Thanks.

motin commented 10 years ago

@qiangxue: Great! Thanks for the quick turnaround :)