use std::path::PathBuf;
use clap::{Parser, Subcommand, command};
use crate::parser::{Rebind, parse_cli_key_val};
mod compose;
mod rainconfig;
pub use compose::*;
pub use rainconfig::*;
#[derive(Parser)]
#[command(author, version, about = "Dotrain cli", long_about = None)]
struct Cli {
#[command(subcommand)]
dotrain: Dotrain,
}
#[derive(Subcommand)]
pub enum Dotrain {
Compose(Compose),
#[command(subcommand)]
Rainconfig(RainconfigInfo),
}
#[derive(Parser, Debug)]
pub struct Compose {
#[arg(short, long)]
input: PathBuf,
#[arg(short, long)]
entrypoint: Vec<String>,
#[arg(short, long, value_parser = parse_cli_key_val)]
bind: Option<Vec<Rebind>>,
#[arg(short, long)]
config: Option<PathBuf>,
#[arg(short, long)]
force: Option<bool>,
#[arg(short, long)]
local_data_only: Option<bool>,
}
#[derive(Subcommand, Debug)]
pub enum RainconfigInfo {
Info,
PrintAll,
Include,
Subgraphs,
}
pub async fn dispatch(dotrain: Dotrain) -> anyhow::Result<()> {
match dotrain {
Dotrain::Compose(cli) => {
println!("{}", compose_target(cli).await?);
}
Dotrain::Rainconfig(v) => match v {
RainconfigInfo::Info => println!("{}", rainconfig::RAINCONFIG_DESCRIPTION),
RainconfigInfo::PrintAll => {
println!("{}", ["- include", "- subgraphs"].join("\n"))
}
RainconfigInfo::Include => {
println!("{}", rainconfig::RAINCONFIG_INCLUDE_DESCRIPTION)
}
RainconfigInfo::Subgraphs => {
println!("{}", rainconfig::RAINCONFIG_SUBGRAPHS_DESCRIPTION)
}
},
};
Ok(())
}
pub async fn main() -> anyhow::Result<()> {
tracing::subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?;
let cli = Cli::parse();
dispatch(cli.dotrain).await
}