Skip to content

Commit

Permalink
enhance(cli): Add Cargo Tauri CLI version to tauri info output (#7713)
Browse files Browse the repository at this point in the history
* enhance(cli): Add Cargo Tauri CLI version to `tauri info` output

* Create enhance-cli-cargo-tauri-cli-version-info.md
  • Loading branch information
i-c-b authored Aug 30, 2023
1 parent 85112e7 commit 1327991
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
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
}

0 comments on commit 1327991

Please sign in to comment.