auric 0.1.4

CLI for the Ember-inspired Auric SPA framework
use clap::Parser;
use std::process::Command;

pub(crate) mod adapter;
pub(crate) mod model;
pub(crate) mod route;
pub(crate) mod template;

#[derive(Debug, Parser)]
pub struct Opts {
    #[command(subcommand)]
    pub subcommand: Subcommand,
}

#[derive(Debug, Parser)]
pub enum Subcommand {
    #[command(name = "adapter")]
    Adapter(adapter::Opts),

    #[command(name = "model")]
    Model(model::Opts),

    #[command(name = "route")]
    Route(route::Opts),

    #[command(name = "template")]
    Template(template::Opts),
}

pub async fn run(subcommand: Subcommand) -> anyhow::Result<()> {
    match subcommand {
        Subcommand::Adapter(adapter::Opts { name }) => adapter::run(name).await,
        Subcommand::Model(model::Opts { name }) => model::run(name).await,
        Subcommand::Route(route::Opts { name }) => route::run(name).await,
        Subcommand::Template(template::Opts { name }) => template::run(name).await,
    }?;

    // make
    eprintln!("==> make");
    let output = Command::new("make").output()?;
    for line in output.stderr.split(|&c| c == b'\n') {
        let line = String::from_utf8(line.to_vec())?;
        eprintln!("{line}");
    }

    Ok(())
}