Skip to content

Commit

Permalink
feat(cli): add version update notification (#141)
Browse files Browse the repository at this point in the history
Implement version check and notification using update-informer
crate. This informs users of new versions with formatted messages
to encourage updates. Updated Cargo.toml and Cargo.lock files
to include new dependencies.
  • Loading branch information
steebchen authored Nov 27, 2024
1 parent 31e5410 commit 221b7a6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ slot.workspace = true
starknet.workspace = true
toml = "0.8"
url.workspace = true
update-informer = { version = "1.1", default-features = false, features = ["github"] }

[[bin]]
name = "slot"
Expand Down
22 changes: 22 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod command;

use crate::command::Command;
use clap::Parser;
use colored::*;
use update_informer::{registry, Check};

/// Slot CLI for Cartridge
#[derive(Parser, Debug)]
Expand All @@ -18,11 +20,31 @@ async fn main() {
env_logger::init();
let cli = Cli::parse();

let name = "cartridge-gg/slot";
let current = env!("CARGO_PKG_VERSION");
let informer = update_informer::new(registry::GitHub, name, current);

match &cli.command.run().await {
Ok(_) => {}
Err(e) => {
eprintln!("{e}");
std::process::exit(1);
}
}

if let Some(version) = informer.check_version().ok().flatten() {
notify_new_version(current, version.to_string().as_str());
}
}

fn notify_new_version(current_version: &str, latest_version: &str) {
println!(
"\n{} {}{} → {}",
"Slot CLI update available:".bold(),
"v".red().bold(),
current_version.red().bold(),
latest_version.green().bold()
);
println!("To upgrade, run: {}", "`slotup`".cyan().bold());
println!("\n")
}

0 comments on commit 221b7a6

Please sign in to comment.