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 · 1 comment · May be fixed by #279
Open

Prevent file overwriting #181

cllns opened this issue Jun 20, 2024 · 1 comment · May be fixed by #279
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
@timriley
Copy link
Member

timriley commented Dec 8, 2024

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.

@stephannv stephannv linked a pull request Dec 8, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants