Skip to content
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

Prevent file overwriting #181

Open
cllns opened this issue Jun 20, 2024 · 0 comments
Open

Prevent file overwriting #181

cllns opened this issue Jun 20, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@cllns
Copy link
Member

cllns commented Jun 20, 2024

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
@cllns cllns self-assigned this Jun 20, 2024
@cllns cllns added the enhancement New feature or request label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Maybe
Development

No branches or pull requests

1 participant