aoc-toolkit 0.1.0-alpha.3

A toolkit for solving Advent of Code problems
Documentation
use std::io;
use std::path::Path;
use std::process::{Command, ExitStatus, Output, Stdio};

use crate::application::run::RunOptions;
use crate::project::Project;

fn command(project: &Project, options: &RunOptions) -> Command {
    let mut command = Command::new("cargo");

    command
        .current_dir(&project.root)
        .env_remove("SESSION_ID")
        .arg("run")
        .arg("--quiet")
        .arg("--profile")
        .arg(&project.config.runner.profile)
        .arg("--manifest-path")
        .arg(project.manifest_path());

    if let Some(binary) = &project.config.runner.binary {
        command.arg("--bin").arg(binary);
    }

    command.arg("--").arg("run");

    if let Some(year) = options.year {
        command.arg("--year").arg(year.to_string());
    }

    if let Some(day) = options.day {
        command.arg("--day").arg(day.to_string());
    }

    if let Some(part) = options.part {
        command.arg("--part").arg(part.to_string());
    }

    if options.all {
        command.arg("--all");
    }

    command
}

pub(crate) fn plan(project: &Project, options: &RunOptions) -> io::Result<Output> {
    command(project, options)
        .arg("--plan")
        .stderr(Stdio::inherit())
        .output()
}

/// Executes the local Rust runner using prepared puzzle inputs.
///
/// # Errors
///
/// Returns an error if the runner process cannot be executed.
pub fn run(project: &Project, options: &RunOptions, input_dir: &Path) -> io::Result<ExitStatus> {
    command(project, options)
        .arg("--input-dir")
        .arg(input_dir)
        .status()
}