Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pyo3-stub-gen = "0.10"
rand = "0.10"
reqwest = "0.13"
rmcp = "1.7.0"
semver = "1.0"
serde = "^1.0"
serde_json = "^1.0"
tdms = "0.3.0"
Expand Down
4 changes: 3 additions & 1 deletion rust/crates/sift_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ indicatif = { workspace = true }
parquet = { workspace = true }
pbjson-types = { workspace = true }
percent-encoding = { workspace = true }
reqwest = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sift_mcp.workspace = true
sift_pbfs = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/sift_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub enum Cmd {

/// Ping the Sift API to verify credentials and connectivity
Ping,

/// Print the installed CLI version and check for a newer release on GitHub
Version,
}

/// Serve the bundled Sift CLI user documentation over HTTP.
Expand Down
1 change: 1 addition & 0 deletions rust/crates/sift_cli/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod import;
pub mod install;
pub mod mcp;
pub mod ping;
pub mod version;

pub struct Context {
pub grpc_uri: String,
Expand Down
78 changes: 78 additions & 0 deletions rust/crates/sift_cli/src/cmd/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use std::{process::ExitCode, time::Duration};

use anyhow::Result;
use crossterm::style::Stylize;
use reqwest::ClientBuilder;
use semver::Version;
use serde::Deserialize;

use crate::util::tty::Output;

const RELEASES_URL: &str = "https://api.github.com/repos/sift-stack/sift/releases?per_page=100";
const TAG_PREFIX: &str = "sift_cli-v";
const USER_AGENT: &str = concat!("sift-cli/", env!("CARGO_PKG_VERSION"));

#[derive(Deserialize)]
struct GithubRelease {
tag_name: String,
}

pub async fn run() -> Result<ExitCode> {
let current_str = env!("CARGO_PKG_VERSION");
let current = Version::parse(current_str)?;

let mut out = Output::new();
out.line(format!("sift-cli {}", current_str.bold()));

match fetch_latest().await {
Ok(Some(latest)) => {
out.line(format!("Latest release: {}", latest.to_string().bold()));
if latest > current {
out.line(format!(
"{}: {} → {}",
"Update available".green(),
current_str.yellow(),
latest.to_string().green(),
));
} else {
out.line("You're on the latest release.".to_string());
}
}
Ok(None) => {
out.line(format!(
"{}: no `{TAG_PREFIX}*` releases found on GitHub",
"warning".yellow(),
));
}
Err(err) => {
out.line(format!(
"{}: unable to check for updates ({err})",
"warning".yellow(),
));
}
}

out.print();
Ok(ExitCode::SUCCESS)
}

async fn fetch_latest() -> Result<Option<Version>> {
let client = ClientBuilder::new()
.user_agent(USER_AGENT)
.timeout(Duration::from_secs(5))
.build()?;

let releases: Vec<GithubRelease> = client
.get(RELEASES_URL)
.send()
.await?
.error_for_status()?
.json()
.await?;

Ok(releases
.into_iter()
.filter_map(|r| r.tag_name.strip_prefix(TAG_PREFIX).map(str::to_string))
.filter_map(|v| Version::parse(&v).ok())
.max())
}
1 change: 1 addition & 0 deletions rust/crates/sift_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn run(clargs: cli::Args) -> Result<ExitCode> {
ConfigCmd::Update(args) => return cmd::config::update(clargs.profile, args),
},
Cmd::Doc(args) => return run_future(cmd::doc::serve(args)),
Cmd::Version => return run_future(cmd::version::run()),
Cmd::Install(cmd) => match cmd {
InstallCmd::Completions(cmd) => match cmd {
cli::CompletionsCmd::Print(args) => return cmd::install::completions::print(args),
Expand Down
Loading