Prevent file overwriting
For our generators, we currently overwrite a path if it already exists. We should fix this so it doesn't happen and show a helpful error message letting them know why.
For some cases (e.g. when we make a parent and a child class), we may want to output (and not overwrite) the parent class but continue on and write the child class.
I'm thinking that we can create Hanami::CLI::Files#create which will raise an error if the path exists and use that everywhere we need to. I guess we won't need an update method, since we use some of the methods on dry-files to update content at a certain place.
# Within Hanami::CLI::Files
def create(path, *content)
if exist?(path)
raise FileAlreadyExistsError.new(path) # this is new
else
write(path, *content)
end
end
This is now half-resolved by #274. We no longer overwrite the file and will exit the CLI command as soon as an existing file is found.
What we need to do next, to truly fix this issue, is some kind of nicer output for the user to understand what has happened.