A CLI tool I am designing takes a path to a config file, as well as an output folder path. Based on the config, the tool which generate different files with different names. If some or all of the files already exist in that folder, there are different ways to handle the error.

  1. If the output folder already has files in it, error out early.

  2. If the output folder already has files in it, warn the user and overwrite any existing files.

  3. If the output folder already has files in it, only generate files that don't already exist and error out instead of overwriting existing files.

  4. Overwrite existing files without warning.

Is there a standard way to handle this use case?

1 Answer 1


Sounds like a setting to be included in the config file or passed via args/kwargs when the command is invoked.

If the config file is missing the setting or the flag is not supplied, default to asking.

When asking, the standard way is to offer to overwrite or skip, plus a cancel option meaning cancel all not yet done. Optionally you can also offer to overwrite all. 3-4 options to choose from isn't too much for a cli tool, imo.

File foo.csv already exists.
[O]verwrite or [S]kip? Or hit [A] to overwrite all or [C] to cancel.

I wouldn't assume skipping or overwriting is desired. If you assume overwriting, I may destroy my data by mistake. If you assume skipping, I may go to my next meeting with my files all ready, only to find that they're the ones from last week that didn't get overwritten.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.