One of the common problems when generating code is the fear of removing business logic when regenerating code in an existing project. To avoid this, we introduced the -n, --no-overwrite option but this doesn't prevent people from forgetting about it or forgetting about a path they don't want to overwrite, and accidentally deleting code they can't recover.
Check if the directory is a git repo. If that's the case, the generator should not allow you to regenerate the project if there are unstaged changes in the working tree. We can also provide a -f, --force option to eliminate this restriction.
I'm also thinking that, when the project is not a git repo, it shouldn't allow you to generate code in a directory that already contains files. Again, this restriction can be removed using -f, --force.
That would be a breaking change right? The default behaviour of the generator would change
Yep but it doesn't really matter yet as we're on 0.x versions. Breaking changes must be expected.
Feature implemented and soon will be released.
From now on, when you generate files:
We also introduced new flag in CLI called --force-write (it is also supported on a library level) and it will allow you to ignore rules provided by this feature
@handrews I saw you like the idea for having such a feature, so just letting you know it is done