use clap::{Parser, Subcommand, ValueEnum};
use crate::runner::config::BackendArg;
#[derive(Parser)]
#[command(
name = "cargo-telar",
bin_name = "cargo telar",
disable_help_subcommand = true
)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Option<TelarCommand>,
}
#[derive(Subcommand)]
pub(crate) enum TelarCommand {
New(NewArgs),
Dev(DevArgs),
Preview(PreviewArgs),
Build(BuildArgs),
Test(TestArgs),
Check(CheckArgs),
Bake,
Transpile,
Doctor,
Fmt(FmtArgs),
Migrate(MigrateArgs),
}
#[derive(clap::Args)]
pub(crate) struct NewArgs {
pub(crate) path: std::path::PathBuf,
#[arg(long)]
pub(crate) name: Option<String>,
#[arg(long, value_enum, default_value = "desktop")]
pub(crate) target: Target,
}
#[derive(clap::Args)]
pub(crate) struct MigrateArgs {
#[arg(long)]
pub(crate) check: bool,
pub(crate) paths: Vec<std::path::PathBuf>,
}
#[derive(clap::Args)]
pub(crate) struct FmtArgs {
#[arg(long)]
pub(crate) check: bool,
pub(crate) paths: Vec<std::path::PathBuf>,
}
#[derive(clap::Args)]
pub(crate) struct CommonArgs {
#[arg(short = 'p', long)]
pub(crate) package: Option<String>,
#[arg(short = 'F', long, value_name = "FEATURES")]
pub(crate) features: Option<String>,
#[arg(long, value_enum)]
pub(crate) target: Option<Target>,
#[arg(long, value_enum)]
pub(crate) backend: Option<BackendArg>,
#[arg(long, value_enum)]
pub(crate) renderer: Option<WebRenderer>,
#[arg(last = true)]
pub(crate) cargo_args: Vec<String>,
}
#[derive(clap::Args)]
pub(crate) struct HotArgs {
#[command(flatten)]
pub(crate) common: CommonArgs,
#[arg(long)]
pub(crate) release: bool,
#[arg(long)]
pub(crate) no_hot_reload: bool,
}
#[derive(clap::Args)]
pub(crate) struct DevArgs {
#[command(flatten)]
pub(crate) hot: HotArgs,
#[arg(long, value_enum)]
pub(crate) devtools: Option<DevtoolsArg>,
}
#[derive(clap::Args)]
pub(crate) struct PreviewArgs {
#[command(flatten)]
pub(crate) hot: HotArgs,
#[arg(long, conflicts_with = "list")]
pub(crate) component: Option<String>,
#[arg(long)]
pub(crate) list: bool,
#[arg(long, value_name = "DIR", conflicts_with = "list")]
pub(crate) png: Option<std::path::PathBuf>,
}
#[derive(clap::Args)]
pub(crate) struct CheckArgs {
#[command(flatten)]
pub(crate) common: CommonArgs,
#[arg(long)]
pub(crate) all_targets: bool,
}
#[derive(clap::Args)]
pub(crate) struct TestArgs {
#[command(flatten)]
pub(crate) common: CommonArgs,
#[arg(long)]
pub(crate) release: bool,
}
#[derive(clap::Args)]
pub(crate) struct BuildArgs {
#[command(flatten)]
pub(crate) common: CommonArgs,
#[arg(long, value_name = "FORMAT")]
pub(crate) format: Option<BuildFormat>,
}
#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum Target {
Desktop,
Android,
Tui,
Web,
}
impl Target {
pub(crate) fn feature(self, renderer: Option<WebRenderer>) -> &'static str {
match self {
Self::Desktop => "desktop",
Self::Android => "android",
Self::Tui => "tui",
Self::Web => match renderer {
Some(WebRenderer::Dom) => "web-dom",
_ => "web",
},
}
}
}
#[derive(Clone, Copy, ValueEnum)]
pub(crate) enum WebRenderer {
Auto,
Canvas,
Dom,
}
impl WebRenderer {
pub(crate) fn as_str(self) -> &'static str {
match self {
Self::Auto => "auto",
Self::Canvas => "canvas",
Self::Dom => "dom",
}
}
}
#[derive(Clone, ValueEnum)]
pub(crate) enum DevtoolsArg {
On,
Off,
}
#[derive(Clone, ValueEnum)]
pub(crate) enum BuildFormat {
Appimage,
Deb,
Dmg,
Nsis,
Apk,
Dir,
}