mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-19 16:41:34 +03:00
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:
parent
85112e7f8f
commit
13279917d4
6
.changes/enhance-cli-cargo-tauri-cli-version-info.md
Normal file
6
.changes/enhance-cli-cargo-tauri-cli-version-info.md
Normal 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.
|
@ -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> =
|
||||
@ -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…
Reference in New Issue
Block a user