Closed motin closed 10 years ago
Could you help test it? Thanks!
Works great over here :)
Help output is correct:
./yii help gii/model
...
--overwrite: boolean, 0 or 1 (defaults to 0)
whether to overwrite all existing code files when in non-interactive mode.
Defaults to false, meaning none of the existing code files will be overwritten.
This option is used only when `--interactive=0`.
...
And the behavior is just as expected:
$ ./yii gii/model --tableName=* --interactive=0
Running 'Model Generator'...
The following files will be generated:
[unchanged] models/Migration.php
No files were chosen to be generated.
$ echo "a-change" >> models/Migration.php
$ ./yii gii/model --tableName=* --interactive=0
Running 'Model Generator'...
The following files will be generated:
[changed] models/Migration.php
No files were chosen to be generated.
$ ./yii gii/model --tableName=* --interactive=0
Running 'Model Generator'...
The following files will be generated:
[changed] models/Migration.php
No files were chosen to be generated.
$ ./yii gii/model --tableName=* --interactive=0 --overwrite=1
Running 'Model Generator'...
The following files will be generated:
[changed] models/Migration.php
Files were generated successfully!
Generating code using template "/local/path/to/yii2-pr-base/extensions/gii/generators/model/default"...
overwrote models/Migration.php
done!
$ ./yii gii/crud --interactive=0 --modelClass=\\app\\models\\Migration --controllerClass=\\app\\controllers\\MigrationController
Running 'CRUD Generator'...
The following files will be generated:
[unchanged] controllers/MigrationController.php
[unchanged] views/migration/_form.php
[unchanged] views/migration/create.php
[unchanged] views/migration/index.php
[unchanged] views/migration/update.php
[unchanged] views/migration/view.php
No files were chosen to be generated.
$ echo "a-change" >> controllers/MigrationController.php
$ ./yii gii/crud --interactive=0 --modelClass=\\app\\models\\Migration --controllerClass=\\app\\controllers\\MigrationController
Running 'CRUD Generator'...
The following files will be generated:
[changed] controllers/MigrationController.php
[unchanged] views/migration/_form.php
[unchanged] views/migration/create.php
[unchanged] views/migration/index.php
[unchanged] views/migration/update.php
[unchanged] views/migration/view.php
No files were chosen to be generated.
$ ./yii gii/crud --interactive=0 --overwrite=1 --modelClass=\\app\\models\\Migration --controllerClass=\\app\\controllers\\MigrationController
Running 'CRUD Generator'...
The following files will be generated:
[changed] controllers/MigrationController.php
[unchanged] views/migration/_form.php
[unchanged] views/migration/create.php
[unchanged] views/migration/index.php
[unchanged] views/migration/update.php
[unchanged] views/migration/view.php
Files were generated successfully!
Generating code using template "/local/path/to/yii2-pr-base/extensions/gii/generators/crud/default"...
overwrote controllers/MigrationController.php
skipped views/migration/_form.php
skipped views/migration/create.php
skipped views/migration/index.php
skipped views/migration/update.php
skipped views/migration/view.php
done!
$ ./yii gii/crud --interactive=1 --overwrite=1 --modelClass=\\app\\models\\Migration --controllerClass=\\app\\controllers\\MigrationController
Running 'CRUD Generator'...
The following files will be generated:
[unchanged] controllers/MigrationController.php
[unchanged] views/migration/_form.php
[unchanged] views/migration/create.php
[unchanged] views/migration/index.php
[unchanged] views/migration/update.php
[unchanged] views/migration/view.php
No files were chosen to be generated.
$ echo "a-change" >> controllers/MigrationController.php
$ ./yii gii/crud --interactive=1 --overwrite=1 --modelClass=\\app\\models\\Migration --controllerClass=\\app\\controllers\\MigrationController
Running 'CRUD Generator'...
The following files will be generated:
[changed] controllers/MigrationController.php
Do you want to overwrite this file? [y,n,ya,na,?]:
Works very nice! Thanks @qiangxue.
One thing to mention (again, sorry) ... shorter release cycles, this would be a very useful fix, which is a typical patch-level update. But I saw over 100 issue open atm. for 2.0.1, which means it will take quite some time to have the feature available with a stable tag. Would be nice, if you could consider releasing Yii 2 more often.
This makes it cumbersome to re-generate models and crud in an automated or scripted manner.
A PR to make this possible was available at https://github.com/yiisoft/yii2/pull/5611 but is no longer relevant since the
--generate
property was removed.Related discussion found in https://github.com/yiisoft/yii2/issues/5610
Use-case: