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
This commit is contained in:
i-c-b 2023-08-30 17:53:37 -05:00 committed by GitHub
parent 85112e7f8f
commit 13279917d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 0 deletions

View File

@ -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.

View File

@ -195,6 +195,7 @@ fn crate_version(
pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<PathBuf>) -> Vec<SectionItem> { pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<PathBuf>) -> Vec<SectionItem> {
let mut items = Vec::new(); let mut items = Vec::new();
if tauri_dir.is_some() || app_dir.is_some() { if tauri_dir.is_some() || app_dir.is_some() {
if let Some(tauri_dir) = tauri_dir { if let Some(tauri_dir) = tauri_dir {
let manifest: Option<CargoManifest> = let manifest: Option<CargoManifest> =
@ -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 items
} }