Here's a README for your Go CLI application:
ifchange is a lightweight CLI tool written in Go that watches a directory for file changes and runs a specified command whenever a change is detected. It's perfect for automating tasks like building and testing code whenever files are updated.
- There are many hot loaders for various languages, Go doesnt have one.
- Other hot reload CLI tools are really complex. this thing is just one file and has a few commands.
To install ifchange, you can use the following one-liner:
(you need Golang installed.) Install go here
go install github.com/erikd234/ifchange@latestMake sure your GOPATH/bin is in your PATH to easily run the ifchange command from anywhere.
ifchange -dir <directory> -cmd "<command>" -only "<regex expression>"-dir: OPTIONAL: Specifies the directory to watch. Defaults to the current directory (./) if not provided.-cmd: The command to execute whenever a file change is detected.-only: OPTIONAL: Regex file match. If you only wanted to do .go files do-only ".go".
ifchange -dir ./src -cmd "go test ./..."This command will watch the ./src directory for changes and run go test ./... whenever a file is modified.
ifchangecontinuously monitors the specified directory and its subdirectories for any file changes.- Upon detecting a change, it triggers the provided command.
- The tool runs in an infinite loop until it receives an interrupt signal (Ctrl+C), at which point it gracefully shuts down.
- Lightweight: Minimal dependencies and simple to use.
- Cross-platform: Works on Linux, macOS, and Windows.
- Customizable: Run any command in response to file changes.
Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.
Let me know if you need any changes or additional sections!