Skip to content

Commit

Permalink
update golem-exmaples and extend app dynamic help with components and…
Browse files Browse the repository at this point in the history
… dependencies
  • Loading branch information
noise64 committed Jan 18, 2025
1 parent 149616e commit 624fc9e
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 141 deletions.
110 changes: 41 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion golem-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ derive_more = { workspace = true }
dirs = "5.0.1"
futures-util = { workspace = true }
glob = "0.3.1"
golem-examples = "1.1.0"
golem-examples = "1.1.1"
h2 = "0.4.7"
http = { workspace = true }
humansize = { workspace = true }
Expand Down
42 changes: 33 additions & 9 deletions golem-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use api_deployment::ApiDeploymentSubcommand;
use clap::{self, Command, Subcommand};
use component::ComponentSubCommand;
use golem_common::uri::oss::uri::ComponentUri;
use golem_examples::cli::NameOrLanguage;
use golem_examples::model::{ComponentName, GuestLanguage, GuestLanguageTier, PackageName};
use golem_wasm_rpc_stubgen::App;
use plugin::PluginSubcommand;
use profile::{ProfileSubCommand, UniversalProfileAdd};
Expand Down Expand Up @@ -104,9 +106,30 @@ pub enum StaticSharedCommand {
#[command(flatten)]
command: diagnose::cli::Command,
},
/// Create a new Golem component from built-in examples
#[command(flatten)]
Examples(golem_examples::cli::Command),
#[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<PackageName>,

/// 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<GuestLanguageTier>,

/// Filter examples by a given guest language
#[arg(short, long, alias = "lang")]
language: Option<GuestLanguage>,
},
}

impl<Ctx> CliCommand<Ctx> for StaticSharedCommand {
Expand All @@ -116,15 +139,14 @@ impl<Ctx> CliCommand<Ctx> for StaticSharedCommand {
diagnose(command);
Ok(GolemResult::Empty)
}
StaticSharedCommand::Examples(golem_examples::cli::Command::ListExamples {
min_tier,
language,
}) => examples::process_list_examples(min_tier, language),
StaticSharedCommand::Examples(golem_examples::cli::Command::New {
StaticSharedCommand::ListExamples { min_tier, language } => {
examples::process_list_examples(min_tier, language)
}
StaticSharedCommand::New {
name_or_language,
package_name,
component_name,
}) => examples::process_new(
} => examples::process_new(
name_or_language.example_name(),
component_name,
package_name,
Expand All @@ -133,6 +155,8 @@ impl<Ctx> CliCommand<Ctx> for StaticSharedCommand {
}
}



/// Commands that are supported by both the OSS and Cloud version
#[derive(Subcommand, Debug)]
#[command()]
Expand Down
11 changes: 6 additions & 5 deletions golem-cli/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@

use std::env;

use crate::model::{ExampleDescription, GolemError, GolemResult};
use golem_examples::model::{
ComponentName, ExampleName, ExampleParameters, GuestLanguage, GuestLanguageTier, PackageName,
TargetExistsResolveMode,
};
use golem_examples::*;

use crate::model::{ExampleDescription, GolemError, GolemResult};

pub fn process_new(
example_name: ExampleName,
component_name: ComponentName,
package_name: Option<PackageName>,
) -> Result<GolemResult, GolemError> {
let examples = GolemExamples::list_all_examples();
let examples = all_standalone_examples();
let example = examples.iter().find(|example| example.name == example_name);
match example {
Some(example) => {
let cwd = env::current_dir().expect("Failed to get current working directory");
match GolemExamples::instantiate(
match instantiate_example(
example,
&ExampleParameters {
component_name,
package_name: package_name
.unwrap_or(PackageName::from_string("golem:component").unwrap()),
target_path: cwd,
},
TargetExistsResolveMode::Fail
) {
Ok(instructions) => Ok(GolemResult::Str(instructions.to_string())),
Err(err) => GolemResult::err(format!("Failed to instantiate component: {err}")),
Expand All @@ -54,7 +55,7 @@ pub fn process_list_examples(
min_tier: Option<GuestLanguageTier>,
language: Option<GuestLanguage>,
) -> Result<GolemResult, GolemError> {
let examples = GolemExamples::list_all_examples()
let examples = all_standalone_examples()
.iter()
.filter(|example| match &language {
Some(language) => example.language == *language,
Expand Down
Loading

0 comments on commit 624fc9e

Please sign in to comment.