Commit cd28ce04 authored by Wohlgemuth, Jason's avatar Wohlgemuth, Jason
Browse files

wip: Initial creation of doctor structs for system software

parent bf1789d6
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
use acorn_lib::doctor::{MemoryInformation, NetworkInformation, SystemInformation, TableFormatPrint};
use acorn_lib::doctor::{MemoryInformation, NetworkInformation, SystemInformation, SystemSoftwareInformation, TableFormatPrint};
use acorn_lib::util::cli::Diagnostic;
use color_eyre::eyre::{Report, Result};
use tracing::warn;
@@ -15,7 +15,7 @@ pub fn run(fix: &bool, interactive: &bool, check: &[Diagnostic]) -> Result<(), R
        unimplemented!("Interactive mode is not implemented yet");
    }
    if should_run(check, Diagnostic::Software) {
        SystemInformation::init().print();
        SystemSoftwareInformation::init().print();
    }
    if should_run(check, Diagnostic::System) {
        SystemInformation::init().print();
+45 −0
Original line number Diff line number Diff line
@@ -10,6 +10,16 @@ pub trait TableFormatPrint {
    fn init() -> Self;
    fn print(self);
}
pub struct InstalledSoftwareData {
    pub version: Option<String>,
    pub path: Option<String>,
}
pub struct InstalledNodeJsData {
    pub version: Option<String>,
    pub path: Option<String>,
    pub npm_version: Option<String>,
    pub npx_version: Option<String>,
}
pub struct MemoryInformation {
    pub total: String,
    pub available: String,
@@ -42,6 +52,12 @@ pub struct SystemInformation {
    pub cpu_arch: String,
    pub cpu_count: String,
}
pub struct SystemSoftwareInformation {
    pub acorn: InstalledSoftwareData,
    pub git: InstalledSoftwareData,
    pub node: InstalledNodeJsData,
    pub vale: InstalledSoftwareData,
}
impl TableFormatPrint for MemoryInformation {
    fn init() -> MemoryInformation {
        let mut sys = System::new_all();
@@ -159,6 +175,35 @@ impl TableFormatPrint for SystemInformation {
        println!("=> {} \n{table}", "System".green().bold());
    }
}
impl TableFormatPrint for SystemSoftwareInformation {
    fn init() -> SystemSoftwareInformation {
        unimplemented!()
    }
    fn print(self) {
        let SystemSoftwareInformation {
            acorn: _,
            git: _,
            node: _,
            vale: _,
        } = self;
        let rows = [
            vec!["Acorn", "Y", "v0.0.0", "/path/to/executable"],
            vec!["Git", "Y", "v0.0.0", "/path/to/executable"],
            vec!["Node.js", "Y", "v0.0.0", "/path/to/executable"],
            vec!["Vale", "Y", "v0.0.0", "/path/to/executable"],
        ];
        let mut table = Table::new();
        table
            .load_preset(UTF8_FULL)
            .apply_modifier(UTF8_ROUND_CORNERS)
            .set_content_arrangement(ContentArrangement::Dynamic)
            .set_header(vec!["Software", "Installed", "Version", "Location"]);
        rows.into_iter().for_each(|row| {
            table.add_row(row);
        });
        println!("=> {} \n{table}", "Memory".green().bold());
    }
}
pub fn print_system_information() {
    SystemInformation::init().print();
    NetworkInformation::init().print();