1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std::path::Path;

use anyhow::{anyhow, Result};

use super::command::Command;

/// Returns `rustup` active toolchain
///
/// Dylint annotation
/// smoelius: Consider carefully whether you need to call this function! In most cases, the toolchain
/// you want is not the one returned by rustup.
pub fn active_toolchain(path: &Path) -> Result<String> {
    let output = Command::new("rustup")
        .sanitize_environment()
        .current_dir(path)
        .args(["show", "active-toolchain"])
        .output()?;
    let stdout = std::str::from_utf8(&output.stdout)?;
    stdout
        .split_once(' ')
        .map(|(s, _)| s.to_owned())
        .ok_or_else(|| anyhow!("Could not determine active toolchain"))
}