dotnethelper 0.2.0

.NET-related helpers for Rust.
Documentation
//! # dotnethelper
//!
//! `dotnethelper` contains [.NET](https://dotnet.microsoft.com/)-related helpers for Rust.

use std::process::{Command, Stdio};

/// Determines whether [.NET](https://dotnet.microsoft.com/) is installed.
///
/// Returns `true` iff `dotnet --version` runs and exits with status 0.
pub fn installed() -> bool {
    Command::new("dotnet")
        .arg("--version")
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .status()
        .map(|s| s.success())
        .unwrap_or(false)
}

/// Returns the trimmed output of `dotnet --version` (e.g. `"9.0.100"`),
/// or `None` if [.NET](https://dotnet.microsoft.com/) is not installed or the probe failed.
pub fn version() -> Option<String> {
    let o = Command::new("dotnet")
        .arg("--version")
        .stderr(Stdio::null())
        .output()
        .ok()?;
    if !o.status.success() {
        return None;
    }
    Some(String::from_utf8_lossy(&o.stdout).trim().to_string())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = installed();
        assert!(result, ".NET is not installed");
    }
}