Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(cli): Add Cargo Tauri CLI version to tauri info output #7713

Merged
merged 2 commits into from
Aug 30, 2023
Merged
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
6 changes: 6 additions & 0 deletions .changes/enhance-cli-cargo-tauri-cli-version-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": minor:enhance
"@tauri-apps/cli": minor:enhance
---

Add version of Rust Tauri CLI installed with Cargo to `tauri info` command.
67 changes: 67 additions & 0 deletions tooling/cli/src/info/packages_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ fn crate_version(

pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<PathBuf>) -> Vec<SectionItem> {
let mut items = Vec::new();

if tauri_dir.is_some() || app_dir.is_some() {
if let Some(tauri_dir) = tauri_dir {
let manifest: Option<CargoManifest> =
Expand Down Expand Up @@ -236,5 +237,71 @@ pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<PathBuf>) -> Vec<Secti
}
}

if let Ok(rust_cli) = std::process::Command::new("cargo")
.arg("tauri")
.arg("-V")
.output()
{
if rust_cli.status.success() {
let stdout = String::from_utf8_lossy(rust_cli.stdout.as_slice()).to_string();
let mut output = stdout.split(' ');
let dep = output.next().unwrap_or_default().to_string();
let version_string = output
.next()
.unwrap_or_default()
.strip_suffix('\n')
.unwrap_or_default()
.to_string();

let version_suffix = match crate_latest_version(&dep) {
Some(target_version) => {
let version = semver::Version::parse(&version_string).unwrap();
let target_version = semver::Version::parse(&target_version).unwrap();
if version < target_version {
Some(format!(
" ({}, latest: {})",
"outdated".yellow(),
target_version.to_string().green()
))
} else {
None
}
}
None => None,
};

items.push(SectionItem::new(
move || {
Some((
format!(
"{} {}: {}{}",
dep,
"[RUST]".dimmed(),
version_string,
version_suffix
.clone()
.map(|s| format!(", {s}"))
.unwrap_or_else(|| "".into())
),
Status::Neutral,
))
},
|| None,
false,
));
} else {
items.push(SectionItem::new(
move || {
Some((
format!("tauri-cli {}: not installed!", "[RUST]".dimmed()),
Status::Neutral,
))
},
|| None,
false,
));
}
}

items
}
Loading