sysid 0.1.0

A simple library providing functionality to generate a 'system ID' that can be used to uniquely identify a computer.
Documentation
use crate::SystemIDBuilder;
use std::process::Command;

impl SystemIDBuilder {
    pub fn add_platform_serial(&mut self) -> &mut Self {
        #[cfg(target_os = "macos")]
        {
            let output = Command::new("ioreg")
                .args(["-c", "IOPlatformExpertDevice", "-d", "2"])
                .output()
                .expect("Failed to execute ioreg");

            self.components.push(
                String::from_utf8_lossy(&output.stdout)
                    .lines()
                    .find(|line| line.contains("IOPlatformSerialNumber"))
                    .and_then(|line| line.split('"').nth_back(1))
                    .expect("Platform serial number not found")
                    .to_string(),
            );
        }
        self
    }

    pub fn add_platform_uuid(&mut self) -> &mut Self {
        #[cfg(target_os = "macos")]
        {
            let output = Command::new("ioreg")
                .args(["-rd1", "-c", "IOPlatformExpertDevice"])
                .output()
                .expect("Failed to execute ioreg");

            self.components.push(
                String::from_utf8_lossy(&output.stdout)
                    .lines()
                    .find(|line| line.contains("IOPlatformUUID"))
                    .and_then(|line| line.split('"').nth_back(1))
                    .expect("Platform UUID not found")
                    .to_string(),
            );
        }
        self
    }

    pub fn add_drive_serial(&mut self) -> &mut Self {
        #[cfg(target_os = "macos")]
        {
            let output = Command::new("system_profiler")
                .args(["SPNVMeDataType"])
                .output()
                .expect("Failed to execute system_profiler");

            self.components.push(
                String::from_utf8_lossy(&output.stdout)
                    .lines()
                    .find(|line| line.trim_start().starts_with("Serial Number:"))
                    .and_then(|line| line.split(':').nth(1))
                    .expect("Drive serial number not found")
                    .trim()
                    .to_string(),
            );
        }
        self
    }

    pub fn add_cpu_brand(&mut self) -> &mut Self {
        #[cfg(target_os = "macos")]
        {
            let output = Command::new("sysctl")
                .args(["-n", "machdep.cpu.brand_string"])
                .output()
                .expect("Failed to execute sysctl");

            self.components
                .push(String::from_utf8_lossy(&output.stdout).trim().to_string());
        }

        self
    }
}