Closed j-bennet closed 5 years ago
@j-bennet Good catch! I like the idea to make things consistent. Let's try to create directories if they don't exist.
Happy to receive a PR for it.
Just want to chime in: most *nix command line tools are happy to create nonexistent files (or new direct subdirectories, if creating a directory structure is the tool's goal), but balk at the idea of creating intermediate subdirectories, unless explicitly told to do so. litecli is designed to deal with a single file at a time, so I don't think it's in the business of creating directories.
As a reference point, when you give sqlite3
a non-existent path, it happily starts the shell; when you actually start making queries, it either creates the database file, or aborts with "unable to open database file" if the directory doesn't exist.
IMO it's okay for litecli
to create the file immediately, but in the nonexistent directory case, a better error message saying so should be enough.
Good point. Perhaps this is too much responsibility for litecli
to create directories.
This PR adds a more clear error message for this case:
Fixed with #46
If I open litecli providing a non-existent file name, but the directory exists, litecli will create a new database:
However, if the path does not exists, litecli will throw an error:
The error also does not say that "path does not exist". This is a bit misleading, because it makes one think the database is there, but it's corrupt.
I think
litecli
should try creating directories in path if they don't exist, and then create a new database. Then the behavior will be consistent between case 1 and case 2.