Skip to content

Commit

Permalink
feat(cli.rs): add active toolchain and rustup to tauri info, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Dec 9, 2021
1 parent feb3a8f commit 28aaec8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/cli.rs-active-toolchain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Add `rustup` version and active rust toolchain to the `info` command output.
40 changes: 40 additions & 0 deletions tooling/cli.rs/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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| {
Expand All @@ -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")
Expand Down

0 comments on commit 28aaec8

Please sign in to comment.