hnhdigital-os / fs-watcher
Provides the ability to watch folders for changes and call a binary in response.
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.3|^8.0
- ext-inotify: *
- hnhdigital-os/php-cli-helper: ^1.1
- laminas/laminas-text: ^2.8
- padraic/phar-updater: ^1.0.6
- symfony/yaml: ^5.2
- vlucas/phpdotenv: ^5.3
Requires (Dev)
- laravel-zero/framework: ^8.4
- mockery/mockery: ^1.4.2
- pestphp/pest: ^1.0
README
Provides the ability to watch folders for changes and call a binary in response.
This package has been developed by H&H|Digital, an Australian botique developer. Visit us at hnh.digital.
Requirements
- PHP 7.3 (min)
- php-inotify (
pecl install inotify
)
Installation
Download the latest build:
curl -o ./fs-watcher -LsS https://github.com/hnhdigital-os/fs-watcher/raw/master/builds/fs-watcher
chmod a+x ./fs-watcher
Move it local bin:
sudo mv ./fs-watcher /usr/local/bin/fs-watcher
Updating
This tool provides a self-update mechanism. Simply run the self-update command.
fs-watcher self-update
How to use
USAGE: fs-watcher <command> [options] [arguments]
config <set|get|reset> [key] [value]
Manage the configuration for this utility.
self-update Check if there is a new version and update.
self-update [--tag=?]
Update this binary to a specific tagged release.
self-update [--check-release=?]
Returns the current binary version.
watch:now [watch-path] [binary-path] [--script-arguments=""]
Specify the path to watch, when a file change is detected
this utility will call the specified binary at the path with the
specific script arguments.
watch:background [watch-path] [binary-path] [--script-arguments=""]
Runs process in the background. Specify the path to watch,
when a file change is detected this utility will call the
specified binary at the path with the specific script arguments.
watch:load Load watchers from a config file.
watch:list List all current watchers.
watch:kill [pid]
Kill a specific process ID for a current watcher.
watch:kill all Kills all the watchers.
watch:log [pid]
View the current log for a specific process ID.
watch:log [--where]
Returns the path of the log files.
watch:log [pid] [--clear]
Clears the logs for a specific process ID.
watch:log [--clear]
Clears all the logs.
watch:now or watch:background
For example, if we want to watch for changes in the /some/folder/example
path and have all changes notified to the executable file /some/bin/binary-file
.
Note: This utility replaces the following placeholders {{root-path}}, {{file-path}} and {{event-id}} in the script-arguments argument with values. Both path arguments do not need quotations as they will be added automatically.
fs-watcher watch:background /some/folder/example /some/bin/binary-file --script-arguments="{{root-path}} {{file-path}} {{event-id}}"
On each file change in the given root folder, the following command execution will occur:
/some/bin/binary-file "/some/folder/example" "/some/folder/example/new-file" 256
watch:load
Instead of calling this utility for each folder you want to watch, you can use the watch:load
command to load a YAML config file.
This config file is in the format:
WATCH-PATH: - BINARY-PATH: SCRIPT-ARGUMENTS
Example:
/some/folder/example: - /some/bin/binary-file: {{root-path}} {{file-path}} {{event-id}}
And then run this to load and start the watcher:
fs-watcher watch:load example.yml
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.