Skip to content

Commit c9ec3be

Browse files
Feature/add automatic cli update (#22)
* Feature/update dependabot (#11) * chore: release v0.1.4 * Feature/dependabot (#3) * chore: release v0.1.4 * Create dependabot.yml * feat: depndabot branch strategy * chore(deps): bump dirs from 5.0.1 to 6.0.0 Bumps [dirs](https://github.com/soc/dirs-rs) from 5.0.1 to 6.0.0. - [Commits](https://github.com/soc/dirs-rs/commits) --- updated-dependencies: - dependency-name: dirs dependency-version: 6.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump reqwest from 0.11.27 to 0.12.19 Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.11.27 to 0.12.19. - [Release notes](https://github.com/seanmonstar/reqwest/releases) - [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md) - [Commits](seanmonstar/reqwest@v0.11.27...v0.12.19) --- updated-dependencies: - dependency-name: reqwest dependency-version: 0.12.19 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update README.md * Update README.md --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: release v0.1.5 * Develop (#15) * Feature/update dependabot (#11) * chore: release v0.1.4 * Feature/dependabot (#3) * chore: release v0.1.4 * Create dependabot.yml * feat: depndabot branch strategy * chore(deps): bump dirs from 5.0.1 to 6.0.0 Bumps [dirs](https://github.com/soc/dirs-rs) from 5.0.1 to 6.0.0. - [Commits](https://github.com/soc/dirs-rs/commits) --- updated-dependencies: - dependency-name: dirs dependency-version: 6.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump reqwest from 0.11.27 to 0.12.19 Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.11.27 to 0.12.19. - [Release notes](https://github.com/seanmonstar/reqwest/releases) - [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md) - [Commits](seanmonstar/reqwest@v0.11.27...v0.12.19) --- updated-dependencies: - dependency-name: reqwest dependency-version: 0.12.19 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update README.md * Update README.md --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update dependabot.yml * feat: Added tool install verifier with cli calls (#14) Before we didn't check if users where missing tools with a expressive incormation enought, this update will highlight the missing tools users needs to security validate for instance python, go and java applications. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Revert "Develop (#15)" This reverts commit 8ac0cfe. * feat: Added tool install verifier with cli calls (#14) Before we didn't check if users where missing tools with a expressive incormation enought, this update will highlight the missing tools users needs to security validate for instance python, go and java applications. * chore: release v0.2.0 * feat: Implemented automatic update information --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 1894037 commit c9ec3be

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

src/main.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::fs;
1111
use std::path::PathBuf;
1212
use std::time::{SystemTime, Duration};
1313
use dirs::cache_dir;
14-
use reqwest::blocking::get;
1514

1615
#[tokio::main]
1716
async fn main() {
@@ -119,16 +118,25 @@ fn check_for_update() {
119118
}
120119
}
121120

122-
// Query crates.io
123-
let resp = get("https://crates.io/api/v1/crates/syncable-cli")
124-
.and_then(|r| r.json::<serde_json::Value>());
125-
if let Ok(json) = resp {
126-
let latest = json["crate"]["max_version"].as_str().unwrap_or("");
127-
let current = env!("CARGO_PKG_VERSION");
128-
if latest != "" && latest != current {
129-
println!(
130-
"\x1b[33m🔔 A new version of sync-ctl is available: {latest} (current: {current})\nRun `cargo install syncable-cli --force` to update.\x1b[0m"
131-
);
121+
// Query crates.io with proper User-Agent header
122+
let client = reqwest::blocking::Client::builder()
123+
.user_agent(format!("syncable-cli/{} ({})", env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_REPOSITORY")))
124+
.build();
125+
126+
if let Ok(client) = client {
127+
let resp = client
128+
.get("https://crates.io/api/v1/crates/syncable-cli")
129+
.send()
130+
.and_then(|r| r.json::<serde_json::Value>());
131+
132+
if let Ok(json) = resp {
133+
let latest = json["crate"]["max_version"].as_str().unwrap_or("");
134+
let current = env!("CARGO_PKG_VERSION");
135+
if latest != "" && latest != current {
136+
println!(
137+
"\x1b[33m🔔 A new version of sync-ctl is available: {latest} (current: {current})\nRun `cargo install syncable-cli --force` to update.\x1b[0m"
138+
);
139+
}
132140
}
133141
}
134142

0 commit comments

Comments
 (0)