moz-cli-version-check
A lightweight version checking library for Mozilla CLI tools.
Features
- Enabled by default: Checks for updates unless
MOZTOOLS_UPDATE_CHECK=0is set - Non-blocking: Runs in background thread, never delays program startup
- Cached: Remote checks are throttled to at most once per interval per tool
- Failure-aware: Failed or blocked remote checks are also throttled
- Shared cache: All tools share
~/.mozbuild/tool-versions.json - Silent failures: Network errors don't affect program operation
- Thread-safe: Safe for concurrent access
Usage
Add to your Cargo.toml:
[]
= "0.2.4"
In your main.rs:
To override the default interval in code:
use Duration;
How It Works
- At program startup, unless
MOZTOOLS_UPDATE_CHECK=0is set, spawn a background thread - The thread checks the cache file (
~/.mozbuild/tool-versions.json) - If the cache is recent (< configured interval), use cached data
- Otherwise, query crates.io API:
https://crates.io/api/v1/crates/<name> - Record the attempt time even if the remote check fails or is blocked
- Update the cache with the latest version info when available
- At program exit, print a warning if a newer version is available
Warning Format
When a newer version is available, users see:
Note: A newer version of socorro-cli is available (0.2.0 > 0.1.0)
Run: cargo binstall socorro-cli
Cache Format
The cache file at ~/.mozbuild/tool-versions.json contains:
Testing
Version checking is enabled by default:
To disable:
Configuration
- Cache location:
~/.mozbuild/tool-versions.json - Default check interval: 24 hours
- Env override:
MOZTOOLS_UPDATE_CHECK_INTERVAL_SECONDS - Network timeout: 5 seconds
- User-Agent:
{tool-name}/version-check
Implementation Details
- Uses
reqwestwith blocking client for HTTP requests - Uses
serde_jsonfor cache file serialization - Thread-safe via
Arc<Mutex<Option<String>>> - Silently fails on any error (network, I/O, parsing)
- Never blocks program execution
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.