use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
use crate::doctor::{Capability, DoctorOptions};
use crate::report::Format;
#[derive(Parser, Debug)]
#[command(name = "bynk", version, about = "The Bynk driver", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand, Debug)]
pub enum Command {
Doctor {
#[arg(default_value = ".")]
input: PathBuf,
#[arg(long, value_enum)]
only: Option<CapabilityArg>,
#[arg(long)]
strict: bool,
#[arg(long, value_enum, default_value = "human")]
format: FormatArg,
},
Dev {
#[arg(default_value = ".")]
path: PathBuf,
#[arg(long)]
context: Option<String>,
#[arg(long)]
inspect: bool,
#[arg(long, default_value_t = 9229)]
inspect_port: u16,
#[arg(last = true)]
wrangler_args: Vec<String>,
},
New {
path: PathBuf,
#[arg(long)]
name: Option<String>,
},
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum CapabilityArg {
Compile,
Test,
Deploy,
Editor,
Build,
}
impl From<CapabilityArg> for Capability {
fn from(a: CapabilityArg) -> Self {
match a {
CapabilityArg::Compile => Capability::Compile,
CapabilityArg::Test => Capability::Test,
CapabilityArg::Deploy => Capability::Deploy,
CapabilityArg::Editor => Capability::Editor,
CapabilityArg::Build => Capability::BuildFromSource,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, ValueEnum)]
pub enum FormatArg {
#[default]
Human,
Short,
Json,
}
impl From<FormatArg> for Format {
fn from(f: FormatArg) -> Self {
match f {
FormatArg::Human => Format::Human,
FormatArg::Short => Format::Short,
FormatArg::Json => Format::Json,
}
}
}
pub fn doctor_options(only: Option<CapabilityArg>, strict: bool) -> DoctorOptions {
DoctorOptions {
only: only.map(Into::into),
strict,
}
}