aoc-toolkit 0.1.0-alpha.1

A toolkit for solving Advent of Code problems
Documentation
use crate::runner::commands::run::Run;
use crate::runner::commands::{Command, CommandResult};
use crate::runner::context::CommandContext;
use clap::{CommandFactory, Parser, Subcommand};

#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

impl Cli {
    pub fn parse_validated() -> Self {
        let cli = Self::parse();

        let result = match &cli.command {
            Commands::Run(command) => command.validate(),
        };

        if let Err(error) = result {
            error.format(&mut Self::command()).exit();
        }

        cli
    }
}

#[derive(Subcommand)]
pub enum Commands {
    /// Runs the specified Advent of Code solution
    Run(Run),
}

impl Command for Commands {
    fn execute(self, ctx: &CommandContext<'_>) -> CommandResult {
        match self {
            Commands::Run(command) => Command::execute(command, ctx),
        }
    }
}