use std::path::PathBuf;
use std::sync::Arc;
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use tokio::fs;
use crate::manifest::Manifest;
#[derive(Parser, Debug)]
pub(crate) struct ServeCommand {
#[arg(long)]
pub open: bool,
#[arg(long)]
pub env: Option<String>,
}
#[derive(Parser, Debug)]
pub(crate) struct BuildCommand {
#[arg(long)]
pub release: bool,
#[arg(long)]
pub env: Option<String>,
#[arg(long)]
pub backend_target: Option<String>,
}
#[derive(Subcommand, Debug)]
pub(crate) enum CliCommand {
Serve(ServeCommand),
Build(BuildCommand),
Clean,
}
#[derive(Parser, Debug)]
#[command(author, version, about = "Command line tool for stellation.", long_about = None)]
pub(crate) struct Cli {
#[arg(short, long, value_name = "FILE", default_value = "stellation.toml")]
pub manifest_path: PathBuf,
#[command(subcommand)]
pub command: CliCommand,
}
impl Cli {
pub async fn load_manifest(&self) -> Result<Arc<Manifest>> {
let manifest_str = fs::read_to_string(&self.manifest_path).await.context(
"failed to load manifest, do you have stellation.toml in the current directory?",
)?;
toml::from_str(&manifest_str)
.map(Arc::new)
.context("failed to parse stellation.toml")
}
}