Skip to content

Commit 1327991

Browse files
authored
enhance(cli): Add Cargo Tauri CLI version to tauri info output (#7713)
* enhance(cli): Add Cargo Tauri CLI version to `tauri info` output * Create enhance-cli-cargo-tauri-cli-version-info.md
1 parent 85112e7 commit 1327991

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": minor:enhance
3+
"@tauri-apps/cli": minor:enhance
4+
---
5+
6+
Add version of Rust Tauri CLI installed with Cargo to `tauri info` command.

tooling/cli/src/info/packages_rust.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ fn crate_version(
195195

196196
pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<PathBuf>) -> Vec<SectionItem> {
197197
let mut items = Vec::new();
198+
198199
if tauri_dir.is_some() || app_dir.is_some() {
199200
if let Some(tauri_dir) = tauri_dir {
200201
let manifest: Option<CargoManifest> =
@@ -236,5 +237,71 @@ pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<PathBuf>) -> Vec<Secti
236237
}
237238
}
238239

240+
if let Ok(rust_cli) = std::process::Command::new("cargo")
241+
.arg("tauri")
242+
.arg("-V")
243+
.output()
244+
{
245+
if rust_cli.status.success() {
246+
let stdout = String::from_utf8_lossy(rust_cli.stdout.as_slice()).to_string();
247+
let mut output = stdout.split(' ');
248+
let dep = output.next().unwrap_or_default().to_string();
249+
let version_string = output
250+
.next()
251+
.unwrap_or_default()
252+
.strip_suffix('\n')
253+
.unwrap_or_default()
254+
.to_string();
255+
256+
let version_suffix = match crate_latest_version(&dep) {
257+
Some(target_version) => {
258+
let version = semver::Version::parse(&version_string).unwrap();
259+
let target_version = semver::Version::parse(&target_version).unwrap();
260+
if version < target_version {
261+
Some(format!(
262+
" ({}, latest: {})",
263+
"outdated".yellow(),
264+
target_version.to_string().green()
265+
))
266+
} else {
267+
None
268+
}
269+
}
270+
None => None,
271+
};
272+
273+
items.push(SectionItem::new(
274+
move || {
275+
Some((
276+
format!(
277+
"{} {}: {}{}",
278+
dep,
279+
"[RUST]".dimmed(),
280+
version_string,
281+
version_suffix
282+
.clone()
283+
.map(|s| format!(", {s}"))
284+
.unwrap_or_else(|| "".into())
285+
),
286+
Status::Neutral,
287+
))
288+
},
289+
|| None,
290+
false,
291+
));
292+
} else {
293+
items.push(SectionItem::new(
294+
move || {
295+
Some((
296+
format!("tauri-cli {}: not installed!", "[RUST]".dimmed()),
297+
Status::Neutral,
298+
))
299+
},
300+
|| None,
301+
false,
302+
));
303+
}
304+
}
305+
239306
items
240307
}

0 commit comments

Comments
 (0)