phase 2
This commit is contained in:
@@ -74,6 +74,22 @@ Certain things should cause the function to return `Err`:
|
||||
- Passing any flags but `-f` or `-i`
|
||||
- Not passing `-i` when the `$DRAWER_KEY` environment variable is undefined
|
||||
|
||||
### Phase 2
|
||||
|
||||
Phase 2 is about error handling. We want to add some variants to `DrawerError` and a `validate` method to `DrawerOperation`
|
||||
that will catch various problems and ensure that we can do the operation correctly. Here are some error cases in no particular order:
|
||||
|
||||
- If the command is `Open` and the drawer file does not exist.
|
||||
- If the command is `Close` and the target path either does not exist, is not a directory, or is not readable.
|
||||
- If the `key` is `EnvVar` but the `$DRAWER_KEY` environment variable is not set, or is not set to a path that exists and is readable.
|
||||
- If the `key` is `Path()` but the path does not exist or is not readable.
|
||||
- If the command is `Open` and the target is a non-empty directory that exists, and the `force` flag is false
|
||||
- If the command is `Close` and the target contains the drawer file (at any level; the target is any parent of the drawer file's path)
|
||||
|
||||
The `validate` method should take `&self` and return `Result<(), DrawerError>`. Let's have `main`, which is currently
|
||||
creating a `DrawerOperation` and not using it, also call `validate` and print out the error if there is one. This means
|
||||
we also need to `impl Display` on `DrawerError`.
|
||||
|
||||
## Commands
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user