You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need the ability to specify files in the home directory as a
`check.path`.
For example, `mysql` uses the following config locations.
> Default options are read from the following files in the given order:
> /etc/my.cnf /etc/mysql/my.cnf /opt/homebrew/etc/my.cnf ~/.my.cnf
We use the one in the home directory to add to the defaults placed in
the other directories.
Here is an example config
```yaml
apiVersion: scope.github.com/v1alpha
kind: ScopeDoctorGroup
metadata:
name: home-directory
description: Cache on a file in user's home directory
spec:
include: when-required
actions:
- name: home-directory
check:
paths:
- ~/.doesnotexist
commands:
- test -f ~/.doesnotexist
fix:
commands:
- touch ~/.doesnotexist
```
Currently, the `make_absolute` function
https://github.com/oscope-dev/scope/blob/0d96462f809d1af5ff08e662d37f4b8813122fd6/scope/src/doctor/check.rs#L574-L580
would receive these parameters
```rust
base_dir = /Users/chris.mcclellan/src/scope/examples
glob = ~/.doesnotexist
```
and return the following string
```txt
/Users/chris.mcclellan/src/scope/examples/~/.doesnotexist
```
Where what we really need is the glob to expand into the user's home directory.
For clarity, specifying the absolute path to the user's directory works right now
```yaml
paths:
- /Users/chris.mcclellan/.doesnotexist
```
but that will obviously be different for every user.
f6d0a9f has some tests illustrating current and desired behavior.
It's also worth noting that environment variables do not expand either.
I did not include that in this PR, but the `shellexpand` library I used for tilde expansion also [allows for environment variable expansion](https://docs.rs/shellexpand/latest/shellexpand/fn.full.html).
I was not sure if we want to allow that, but it is a simple change to make if that is desired.
While implementing this, I also noticed that `check` and `fix` `commands` are not expanded.
https://github.com/oscope-dev/scope/blob/41cb86feea7e913ed3eb647aecfbf96625f6f733/examples/.scope/home-directory.yaml#L14-L27
For a consistent user experience, I figured these should expand as well, removing the need for calling a bash script in the commit above.
Testing
---
I added unit tests for this feature, but it can also be tested with this command.
```sh
cargo run -- doctor run --working-dir examples --only home-directory
--cache-dir . --progress=plain
```
- Run it once to verify the check fails and fix works.
- Inspect the `cache-file.json` file to verify the file in the home directory is cached
- Run it again to verify the check succeeds
0 commit comments