chshersh / iris

🌈 Haskell CLI Framework supporting Command Line Interface Guidelines
https://hackage.haskell.org/package/iris
Mozilla Public License 2.0
181 stars 22 forks source link

Utility to write files with protection to avoid file override #14

Open chshersh opened 2 years ago

chshersh commented 2 years ago

When using the writeFile function, the program silently overrides the file content. In this case, you may lose your previous content if you're careful enough.

I propose to create a new module Iris.IO and add a protected writeFile function that:

  1. Takes an argument of type: data ActionFlag = Ask | Force
  2. When Ask is given, it checks for file existence and asks a question, whether user wants to override file content.
martinhelmer commented 1 year ago

how should the function behave if "Ask" is combined with NonInteractive? I would say that the sensible default is to NOT overwrite. Also, what's the response to "overwrite? NO" ? throw an exception?

Edit: To access the Interactive setting the function would need to run within the App context though.