golem_examples/
cli.rs

1use clap::*;
2
3use crate::model::{
4    ComponentName, ComposableAppGroupName, ExampleName, GuestLanguage, GuestLanguageTier,
5    PackageName,
6};
7
8#[derive(Args, Debug)]
9#[group(required = true, multiple = false)]
10pub struct NameOrLanguage {
11    /// Name of the example to use
12    #[arg(short, long, group = "ex")]
13    pub example: Option<ExampleName>,
14
15    /// Language to use for it's default example
16    #[arg(short, long, alias = "lang", group = "ex")]
17    pub language: Option<GuestLanguage>,
18}
19
20impl NameOrLanguage {
21    /// Gets the selected example's name
22    pub fn example_name(&self) -> ExampleName {
23        self.example
24            .clone()
25            .unwrap_or(ExampleName::from_string(format!(
26                "{}-default",
27                self.language.unwrap_or(GuestLanguage::Rust).id()
28            )))
29    }
30}
31
32#[derive(Subcommand, Debug)]
33#[command()]
34pub enum Command {
35    /// Create a new Golem component from built-in examples
36    #[command()]
37    New {
38        #[command(flatten)]
39        name_or_language: NameOrLanguage,
40
41        /// The package name of the generated component (in namespace:name format)
42        #[arg(short, long)]
43        package_name: Option<PackageName>,
44
45        /// The new component's name
46        component_name: ComponentName,
47    },
48
49    /// Lists the built-in examples available for creating new components
50    #[command()]
51    ListExamples {
52        /// The minimum language tier to include in the list
53        #[arg(short, long)]
54        min_tier: Option<GuestLanguageTier>,
55
56        /// Filter examples by a given guest language
57        #[arg(short, long, alias = "lang")]
58        language: Option<GuestLanguage>,
59    },
60
61    /// Lists the built-in composable app templates available for creating new components
62    #[command()]
63    ListAppExamples {
64        /// Filter examples by a given guest language
65        #[arg(short, long, alias = "lang")]
66        language: Option<GuestLanguage>,
67
68        /// Filter examples by a given composable group name
69        #[arg(short, long, alias = "group")]
70        group: Option<ComposableAppGroupName>,
71    },
72
73    NewAppComponent {
74        /// The component name (and package name) of the generated component (in namespace:name format)
75        component_name: PackageName,
76
77        /// Component language
78        #[arg(short, long, alias = "lang")]
79        language: GuestLanguage,
80    },
81}
82
83#[derive(Parser, Debug)]
84#[command(author, version, about, long_about = None, rename_all = "kebab-case")]
85pub struct GolemCommand {
86    #[command(subcommand)]
87    pub command: Command,
88}