use clap::*;
use crate::model::{ComponentName, ExampleName, GuestLanguage, GuestLanguageTier, PackageName};
#[derive(Args, Debug)]
#[group(required = true, multiple = false)]
pub struct NameOrLanguage {
#[arg(short, long, group = "ex")]
pub example: Option<ExampleName>,
#[arg(short, long, alias = "lang", group = "ex")]
pub language: Option<GuestLanguage>,
}
impl NameOrLanguage {
pub fn example_name(&self) -> ExampleName {
self.example
.clone()
.unwrap_or(ExampleName::from_string(format!(
"{}-default",
self.language.clone().unwrap_or(GuestLanguage::Rust).id()
)))
}
}
#[derive(Subcommand, Debug)]
#[command()]
pub enum Command {
#[command()]
New {
#[command(flatten)]
name_or_language: NameOrLanguage,
#[arg(short, long)]
package_name: Option<PackageName>,
component_name: ComponentName,
},
#[command()]
ListExamples {
#[arg(short, long)]
min_tier: Option<GuestLanguageTier>,
#[arg(short, long, alias = "lang")]
language: Option<GuestLanguage>,
},
}
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None, rename_all = "kebab-case")]
pub struct GolemCommand {
#[command(subcommand)]
pub command: Command,
}