Add CLI --help examples and scheduling documentation#74
Add CLI --help examples and scheduling documentation#74markcallen wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the usability of the project’s three CLI tools by enhancing --help output with real-world examples, and adds centralized documentation for running the tools on schedules (cron/launchd), linked from the root README.
Changes:
- Add custom
flag.Usagefunctions to include an “Examples” section in--helpfordev-cache,git-cleaner, andmac-cache-cleaner. - Add
docs/scheduling.mdwith cron and macOS launchd scheduling examples plus operational notes. - Link the new scheduling guide from the root
README.md.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
dev-cache/main.go |
Adds custom flag.Usage output with examples for common workflows. |
git-cleaner/main.go |
Adds custom flag.Usage output with scan/clean examples. |
mac-cache-cleaner/main.go |
Adds custom flag.Usage output with examples for targets/cleaning. |
docs/scheduling.md |
New scheduling guide covering cron and launchd usage patterns. |
README.md |
Adds a link to the new scheduling documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func init() { | ||
| flag.Usage = func() { | ||
| out := flag.CommandLine.Output() | ||
| fmt.Fprintf(out, "Usage: dev-cache [flags]\n\nFlags:\n") | ||
| flag.PrintDefaults() | ||
| fmt.Fprintf(out, "\nExamples:\n") | ||
| fmt.Fprintf(out, " dev-cache # Scan default path from config\n") | ||
| fmt.Fprintf(out, " dev-cache --scan ~/projects # Scan specific directory\n") | ||
| fmt.Fprintf(out, " dev-cache --clean --yes # Clean without confirmation\n") | ||
| fmt.Fprintf(out, " dev-cache --languages node,rust # Only node and rust caches\n") | ||
| } |
There was a problem hiding this comment.
The custom --help output omits the supported -version/--version option (handled via checkVersionFlag), so users won't discover it from help. Consider adding a short line for -version/--version in the usage output near the flags section.
| func init() { | ||
| flag.Usage = func() { | ||
| out := flag.CommandLine.Output() | ||
| fmt.Fprintf(out, "Usage: git-cleaner --scan <directory> [flags]\n\nFlags:\n") | ||
| flag.PrintDefaults() | ||
| fmt.Fprintf(out, "\nExamples:\n") | ||
| fmt.Fprintf(out, " git-cleaner --scan ~/src # Scan for .git directories\n") | ||
| fmt.Fprintf(out, " git-cleaner --scan ~/src --clean # Optimize with git gc\n") | ||
| } |
There was a problem hiding this comment.
The custom --help output omits the supported -version/--version option (handled via checkVersionFlag), so users won't discover it from help. Consider adding a short line for -version/--version in the usage output near the flags section.
| func init() { | ||
| flag.Usage = func() { | ||
| out := flag.CommandLine.Output() | ||
| fmt.Fprintf(out, "Usage: mac-cache-cleaner [flags]\n\nFlags:\n") | ||
| flag.PrintDefaults() | ||
| fmt.Fprintf(out, "\nExamples:\n") | ||
| fmt.Fprintf(out, " mac-cache-cleaner # Scan all targets (dry-run)\n") | ||
| fmt.Fprintf(out, " mac-cache-cleaner --clean # Run cleanup commands\n") | ||
| fmt.Fprintf(out, " mac-cache-cleaner --targets docker,npm # Specific targets only\n") | ||
| } |
There was a problem hiding this comment.
The custom --help output omits the supported -version/--version option (handled via checkVersionFlag), so users won't discover it from help. Consider adding a short line for -version/--version in the usage output near the flags section.
| 0 3 * * 0 /usr/local/bin/dev-cache --scan ~/src --clean --yes >> ~/cache-cleaner.log 2>&1 | ||
| 0 3 * * 0 /usr/local/bin/git-cleaner --scan ~/src --clean >> ~/cache-cleaner.log 2>&1 | ||
| 0 3 * * 0 /usr/local/bin/mac-cache-cleaner --clean >> ~/cache-cleaner.log 2>&1 |
There was a problem hiding this comment.
The cron examples use "~/..." paths. Tilde expansion is shell-dependent and is not guaranteed in cron (commonly executed under /bin/sh), so these commands may fail on some systems. Prefer absolute paths or use $HOME for the scan path and log path in the examples.
| 0 3 * * 0 /usr/local/bin/dev-cache --scan ~/src --clean --yes >> ~/cache-cleaner.log 2>&1 | |
| 0 3 * * 0 /usr/local/bin/git-cleaner --scan ~/src --clean >> ~/cache-cleaner.log 2>&1 | |
| 0 3 * * 0 /usr/local/bin/mac-cache-cleaner --clean >> ~/cache-cleaner.log 2>&1 | |
| 0 3 * * 0 /usr/local/bin/dev-cache --scan "$HOME/src" --clean --yes >> "$HOME/cache-cleaner.log" 2>&1 | |
| 0 3 * * 0 /usr/local/bin/git-cleaner --scan "$HOME/src" --clean >> "$HOME/cache-cleaner.log" 2>&1 | |
| 0 3 * * 0 /usr/local/bin/mac-cache-cleaner --clean >> "$HOME/cache-cleaner.log" 2>&1 |
| Notes: | ||
| - Update binary paths based on your install location (`which dev-cache`, `which git-cleaner`, `which mac-cache-cleaner`). | ||
| - Keep log redirection enabled for troubleshooting. | ||
|
|
||
| ## launchd (macOS) | ||
|
|
||
| Create `~/Library/LaunchAgents/com.cache-cleaner.weekly.plist`: | ||
|
|
||
| ```xml | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>Label</key> | ||
| <string>com.cache-cleaner.weekly</string> | ||
|
|
||
| <key>ProgramArguments</key> | ||
| <array> | ||
| <string>/usr/local/bin/mac-cache-cleaner</string> | ||
| <string>--clean</string> | ||
| </array> |
There was a problem hiding this comment.
For scheduled runs, environment differs from interactive shells (cron/launchd often have a minimal PATH). Since mac-cache-cleaner can invoke tools like brew/docker/npm from its config, the docs should mention ensuring PATH is set appropriately (e.g., via a PATH=... line in crontab and EnvironmentVariables in the launchd plist). Otherwise scheduled cleanups may fail even if the mac-cache-cleaner binary path is absolute.
Summary
flag.Usageoutput withExamplessections for:dev-cachegit-cleanermac-cache-cleanerdocs/scheduling.md:cronexamples for all three toolslaunchdplist example for macOSbrew servicesIssues
Validation
make test