applicationsonline / librarian-chef

Librarian-Chef - A Bundler for your Chef Cookbooks. Librarian is at: https://github.com/applicationsonline/librarian.
http://applicationsonline.com/
MIT License
360 stars 55 forks source link

Data loss should be opt-in #22

Open zyegfryed opened 10 years ago

zyegfryed commented 10 years ago

As this time of writing, running librarian-chef with an existing cookbooks directory will wipe out all the data before installing the dependencies. Without letting the user know what's going behind the scene. This is an issue when you're beginner and you start writing recipes and then want to manage dependencies to test them, and everything is in the same cookbooks directory. Like detailed in First steps with Chef tutorial for example.

We should never destroy any data without informing the user before.

A proposed solution would be to explain to the user what's going and prompting him/her for it's agreement, like the following:

A 'cookbook' directory already exists. Proceeding will remove the current
directory and might lead to data loss. Are you sure to continue? (y/N)

When the answer is negative (no/n), the program exits without any further ado. When the answer is positive (yes/y), the program behaves the same as currently.

We should be protective regarding the user data, hence the capital letter N as default choice. So, even when a user hit [ENTER] without reading the warning message his/her recipes are safe.

For advanced usage, we can also provide a flag to prevent the prompt, like -y/--assumeyes (apt/yum style) or -f/--force (rm style) which will enforce the destructive behavior.

PS: I learned that lesson the hard way and want to prevent anyone to experience this "WTF?!" moment when your data is vacuumed in space. PPS: I'm not a Rubyist but might be able to land a patch with some help and good pointers.