Allow procs to be passed to the watch method
- Dominant language
- Crystal
- Stars
- 10
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
It would be useful if a `proc` could be passed as the second argument of the `watch` method to allow custom commands based on the name of the changed file. For example:
```crystal
custom_command = ->(file : String) : String? do
# ... build a command based on the changed file, return the string
end
Watch.watch "./**/*.cr", custom_command
```
An example usage could be running the respective spec file for any file in the src/ dir:
```crystal
# runs matching spec for any file in /src
run_spec = ->(file : String) : String? do
spec = file
.sub(/^\.\/src\//, "./spec/")
.sub(/(_spec|_flow)?\.cr$/, "_spec.cr")
if File.exists?(spec)
puts %(> running "#{spec}")
"crystal spec #{spec}"
else
puts %(> matching spec "#{spec}" does not exist)
end
end
Watch.watch "./**/*.cr", run_spec
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.