use std::process::exit;

use cmd_exists::cmd_exists;

mod doctor;
mod service;

fn main() {
    if cmd_exists("dinitctl").is_err() {
        eprintln!(
            "This, obviously, is a tool for the Dinit init system, which doesn't seem to be installed on your distro.\nSwapping your existing init system is risky and can make your distro unbootable.\nDistros like Artix or Chimera Linux provide ISOs with Dinit as an option."
        );
        exit(1);
    }
    let mut summary_mode = false;
    let mut stopped_only = false;
    let args: Vec<String> = std::env::args().collect();
    if let Some(arg1) = args.get(1).map(|s| s.as_str()) {
        match arg1 {
            "sum" | "summary-only" | "-su" => {
                summary_mode = true;
            }
            "sto" | "stopped-only" | "-st" => {
                stopped_only = true;
            }
            _ => {}
        }
    }
    if let Some(summary) = doctor::run_doctor_check(summary_mode, stopped_only) {
        println!("{}", summary);
    }
}
