feat(cli.rs): add active toolchain and rustup to tauri info, closes #2730 (#2986)

This commit is contained in:
Amr Bashir
2021-12-09 06:28:26 +02:00
committed by GitHub
parent feb3a8f896
commit 28aaec87e2
2 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"cli.rs": patch
---
Add `rustup` version and active rust toolchain to the `info` command output.

View File

@@ -328,6 +328,32 @@ fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
Ok(versions)
}
fn get_active_rust_toolchain() -> crate::Result<Option<String>> {
let mut cmd;
#[cfg(target_os = "windows")]
{
cmd = Command::new("cmd");
cmd.arg("/c").arg("rustup");
}
#[cfg(not(target_os = "windows"))]
{
cmd = Command::new("rustup")
}
let output = cmd.args(["show", "active-toolchain"]).output()?;
let toolchain = if output.status.success() {
Some(
String::from_utf8_lossy(&output.stdout)
.replace("\n", "")
.replace("\r", ""),
)
} else {
None
};
Ok(toolchain)
}
struct InfoBlock {
section: bool,
key: &'static str,
@@ -513,6 +539,15 @@ impl Info {
}
InfoBlock::new("Rust environment").section().display();
VersionBlock::new(
" rustup",
get_version("rustup", &[]).unwrap_or_default().map(|v| {
let mut s = v.split(' ');
s.next();
s.next().unwrap().to_string()
}),
)
.display();
VersionBlock::new(
" rustc",
get_version("rustc", &[]).unwrap_or_default().map(|v| {
@@ -531,6 +566,11 @@ impl Info {
}),
)
.display();
VersionBlock::new(
" toolchain",
get_active_rust_toolchain().unwrap_or_default(),
)
.display();
if let Some(app_dir) = app_dir {
InfoBlock::new("App directory structure")