diff --git a/src/cli.rs b/src/cli.rs index 33018e5..b5915a9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,32 +7,53 @@ use std::env; #[derive(Args, Debug)] #[group(required = true, multiple = false)] -struct NameOrLanguage { +pub struct NameOrLanguage { + /// Name of the example to use #[arg(short, long, group = "ex")] example: Option, + /// Language to use for it's default example #[arg(short, long, alias = "lang", group = "ex")] language: Option, } +impl NameOrLanguage { + /// Gets the selected example's name + 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()] -enum Command { +pub enum Command { + /// Create a new Golem component from built-in examples #[command()] New { #[command(flatten)] name_or_language: NameOrLanguage, + /// The package name of the generated component (in namespace:name format) #[arg(short, long)] package_name: Option, + /// The new component's name component_name: ComponentName, }, + + /// Lists the built-in examples available for creating new components #[command()] ListExamples { + /// The minimum language tier to include in the list #[arg(short, long)] min_tier: Option, + /// Filter examples by a given guest language #[arg(short, long, alias = "lang")] language: Option, }, @@ -40,7 +61,7 @@ enum Command { #[derive(Parser, Debug)] #[command(author, version, about, long_about = None, rename_all = "kebab-case")] -struct GolemCommand { +pub struct GolemCommand { #[command(subcommand)] command: Command, } @@ -53,18 +74,7 @@ pub fn main() { component_name, package_name, } => { - let example_name = - name_or_language - .example - .clone() - .unwrap_or(ExampleName::from_string(format!( - "{}-default", - name_or_language - .language - .clone() - .unwrap_or(GuestLanguage::Rust) - .id() - ))); + let example_name = name_or_language.example_name(); let examples = GolemExamples::list_all_examples(); let example = examples.iter().find(|example| example.name == example_name); match example { diff --git a/src/lib.rs b/src/lib.rs index a92048b..fc531c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::{fs, io}; +pub mod cli; pub mod model; pub trait Examples {