Skip to content

Commit bdb9f99

Browse files
authored
CLI final command naming related changes for 1.5.0 (#3262)
* agent type listing and get cleanup * doc comment, naming and module cleanups
1 parent e1f3059 commit bdb9f99

12 files changed

Lines changed: 263 additions & 221 deletions

File tree

cli/golem-cli/src/command.rs

Lines changed: 193 additions & 189 deletions
Large diffs are not rendered by default.

cli/golem-cli/src/command_handler/app/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::log::{
3838
logged_failed_to, logged_finished_or_failed_to, logln,
3939
};
4040
use crate::model::GuestLanguage;
41+
use crate::model::agent::view::AgentTypeView;
4142
use crate::model::app::{
4243
AppBuildStep, ApplicationComponentSelectMode, BuildConfig, CleanMode, DynamicHelpSections,
4344
};
@@ -59,6 +60,7 @@ use futures_util::{StreamExt, TryStreamExt, stream};
5960
use golem_client::api::{ApplicationClient, ComponentClient, EnvironmentClient};
6061
use golem_client::model::{ApplicationCreation, DeploymentCreation, DeploymentRollback};
6162
use golem_common::model::account::AccountId;
63+
use golem_common::model::agent::AgentTypeName;
6264
use golem_common::model::agent::DeployedRegisteredAgentType;
6365
use golem_common::model::agent::schema_evolution::validate_schema_evolution;
6466
use golem_common::model::application::ApplicationName;
@@ -414,6 +416,31 @@ impl AppCommandHandler {
414416
Ok(())
415417
}
416418

419+
pub async fn cmd_get_agent_type(&self, agent_type_name: AgentTypeName) -> anyhow::Result<()> {
420+
let environment = self
421+
.ctx
422+
.environment_handler()
423+
.resolve_environment(EnvironmentResolveMode::Any)
424+
.await?;
425+
426+
let Some(agent_type) = self
427+
.get_agent_type_by_name(&environment, agent_type_name.0.as_str())
428+
.await?
429+
else {
430+
log_error(format!(
431+
"Agent type {} not found",
432+
agent_type_name.0.log_color_highlight()
433+
));
434+
bail!(NonSuccessfulExit);
435+
};
436+
437+
self.ctx
438+
.log_handler()
439+
.log_view(&AgentTypeView::new(&agent_type, true));
440+
441+
Ok(())
442+
}
443+
417444
pub async fn list_agent_types(
418445
&self,
419446
environment: &ResolvedEnvironmentIdentity,

cli/golem-cli/src/command_handler/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use self::agent_secret::AgentSecretCommandHandler;
1616
use self::resource_definition::ResourceDefinitionCommandHandler;
1717
use self::retry_policy::RetryPolicyCommandHandler;
18+
use crate::command::agent_type::AgentTypeSubcommand;
1819
#[cfg(feature = "server-commands")]
1920
use crate::command::server::ServerSubcommand;
2021
use crate::command::{
@@ -364,9 +365,6 @@ impl<Hooks: CommandHandlerHooks + 'static> CommandHandler<Hooks> {
364365
.cmd_redeploy_workers(component_name.component_name)
365366
.await
366367
}
367-
GolemCliSubcommand::ListAgentTypes {} => {
368-
self.ctx.app_handler().cmd_list_agent_types().await
369-
}
370368
GolemCliSubcommand::Exec { subcommand } => {
371369
self.ctx.app_handler().exec_custom_command(subcommand).await
372370
}
@@ -387,6 +385,17 @@ impl<Hooks: CommandHandlerHooks + 'static> CommandHandler<Hooks> {
387385
GolemCliSubcommand::Agent { subcommand } => {
388386
self.ctx.worker_handler().handle_command(subcommand).await
389387
}
388+
GolemCliSubcommand::AgentType { subcommand } => match subcommand {
389+
AgentTypeSubcommand::List => {
390+
self.ctx.app_handler().cmd_list_agent_types().await
391+
}
392+
AgentTypeSubcommand::Get { agent_type_name } => {
393+
self.ctx
394+
.app_handler()
395+
.cmd_get_agent_type(agent_type_name)
396+
.await
397+
}
398+
},
390399
GolemCliSubcommand::Api { subcommand } => {
391400
self.ctx.api_handler().handle_command(subcommand).await
392401
}

cli/golem-cli/src/command_handler/partial_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::model::app::{ApplicationComponentSelectMode, DynamicHelpSections};
2525
use crate::model::component::ComponentNameMatchKind;
2626
use crate::model::format::Format;
2727
use crate::model::text::fmt::{DecoratedIndent, log_text_view};
28-
use crate::model::text::help::{AvailableFunctionNamesHelp, EnvironmentNameHelp, WorkerNameHelp};
28+
use crate::model::text::help::{AgentNameHelp, AvailableFunctionNamesHelp, EnvironmentNameHelp};
2929
use colored::Colorize;
3030
use indoc::indoc;
3131
use std::sync::Arc;
@@ -186,9 +186,9 @@ impl ErrorHandler {
186186
}
187187
Ok(())
188188
}
189-
GolemCliCommandPartialMatch::WorkerInvokeMissingWorkerName => {
189+
GolemCliCommandPartialMatch::AgentInvokeMissingAgentName => {
190190
logln("");
191-
log_text_view(&WorkerNameHelp);
191+
log_text_view(&AgentNameHelp);
192192
logln("");
193193

194194
self.ctx.silence_app_context_init().await;

cli/golem-cli/src/command_handler/resource_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::command::api::resource_definition::ResourceDefinitionSubcommand;
15+
use crate::command::resource_definition::ResourceDefinitionSubcommand;
1616
use crate::command_handler::Handlers;
1717
use crate::context::Context;
1818
use crate::error::NonSuccessfulExit;

cli/golem-cli/src/command_handler/retry_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::command::api::retry_policy::RetryPolicySubcommand;
15+
use crate::command::retry_policy::RetryPolicySubcommand;
1616
use crate::command_handler::Handlers;
1717
use crate::context::Context;
1818
use crate::error::NonSuccessfulExit;

cli/golem-cli/src/command_handler/worker/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod stream;
1616
mod stream_output;
1717

1818
use crate::command::shared_args::{
19-
AgentIdArgs, PostDeployArgs, StreamArgs, WorkerFunctionArgument, WorkerFunctionName,
19+
AgentFunctionArgument, AgentFunctionName, AgentIdArgs, PostDeployArgs, StreamArgs,
2020
};
2121
use crate::command::worker::AgentSubcommand;
2222
use crate::command_handler::Handlers;
@@ -34,7 +34,7 @@ use crate::model::deploy::{TryUpdateAllWorkersResult, WorkerUpdateAttempt};
3434
use crate::model::invoke_result_view::InvokeResultView;
3535
use crate::model::text::fmt::{log_fuzzy_match, log_text_view};
3636
use crate::model::text::help::{
37-
AvailableAgentConstructorsHelp, AvailableFunctionNamesHelp, WorkerNameHelp,
37+
AgentNameHelp, AvailableAgentConstructorsHelp, AvailableFunctionNamesHelp,
3838
};
3939
use crate::model::text::worker::{
4040
FileNodeView, WorkerCreateView, WorkerFilesView, WorkerGetView, format_agent_name_match,
@@ -312,8 +312,8 @@ impl WorkerCommandHandler {
312312
async fn cmd_invoke(
313313
&self,
314314
agent_name: AgentIdArgs,
315-
function_name: &WorkerFunctionName,
316-
arguments: Vec<WorkerFunctionArgument>,
315+
function_name: &AgentFunctionName,
316+
arguments: Vec<AgentFunctionArgument>,
317317
trigger: bool,
318318
idempotency_key: Option<IdempotencyKey>,
319319
no_stream: bool,
@@ -579,7 +579,7 @@ impl WorkerCommandHandler {
579579

580580
async fn cmd_repl_stream(
581581
&self,
582-
agent_type_name: String,
582+
agent_type_name: AgentTypeName,
583583
parameters: String,
584584
idempotency_key: IdempotencyKey,
585585
phantom_id: Option<Uuid>,
@@ -599,10 +599,10 @@ impl WorkerCommandHandler {
599599
let Some(agent_type) = self
600600
.ctx
601601
.app_handler()
602-
.get_agent_type_by_name(&environment, &agent_type_name)
602+
.get_agent_type_by_name(&environment, agent_type_name.0.as_str())
603603
.await?
604604
else {
605-
bail!("Agent type not found: {}", agent_type_name);
605+
bail!("Agent type not found: {}", agent_type_name.0);
606606
};
607607

608608
let typed_parameters = DataValue::try_from_untyped_json(
@@ -813,7 +813,7 @@ impl WorkerCommandHandler {
813813

814814
async fn cmd_list(
815815
&self,
816-
agent_type_name: Option<String>,
816+
agent_type_name: Option<AgentTypeName>,
817817
component_name: Option<ComponentName>,
818818
filters: Vec<String>,
819819
scan_cursor: Option<ScanCursor>,
@@ -898,7 +898,7 @@ impl WorkerCommandHandler {
898898

899899
async fn resolve_list_components(
900900
&self,
901-
agent_type_name: Option<String>,
901+
agent_type_name: Option<AgentTypeName>,
902902
component_name: Option<ComponentName>,
903903
filters: Vec<String>,
904904
) -> anyhow::Result<(Vec<ComponentDto>, Vec<String>)> {
@@ -912,16 +912,16 @@ impl WorkerCommandHandler {
912912
.environment_handler()
913913
.resolve_environment(EnvironmentResolveMode::Any)
914914
.await?;
915-
debug!("Finding agent type {}", agent_type_name);
915+
debug!("Finding agent type {}", agent_type_name.0);
916916
let Some(agent_type) = self
917917
.ctx
918918
.app_handler()
919-
.get_agent_type_by_name(&environment, &agent_type_name)
919+
.get_agent_type_by_name(&environment, agent_type_name.0.as_str())
920920
.await?
921921
else {
922922
log_error(format!(
923923
"Agent type {} not found",
924-
agent_type_name.log_color_highlight()
924+
agent_type_name.0.log_color_highlight()
925925
));
926926
bail!(NonSuccessfulExit)
927927
};
@@ -2232,7 +2232,7 @@ impl WorkerCommandHandler {
22322232
agent_name.log_color_error_highlight()
22332233
));
22342234
logln("");
2235-
log_text_view(&WorkerNameHelp);
2235+
log_text_view(&AgentNameHelp);
22362236
bail!(NonSuccessfulExit);
22372237
}
22382238
};
@@ -2253,7 +2253,7 @@ impl WorkerCommandHandler {
22532253
"Deploy the component that defines this agent type or specify environment/application/account prefixes.",
22542254
);
22552255
logln("");
2256-
log_text_view(&WorkerNameHelp);
2256+
log_text_view(&AgentNameHelp);
22572257
bail!(NonSuccessfulExit);
22582258
};
22592259

@@ -2303,7 +2303,7 @@ impl WorkerCommandHandler {
23032303
name = name.log_color_highlight()
23042304
));
23052305
logln("");
2306-
log_text_view(&WorkerNameHelp);
2306+
log_text_view(&AgentNameHelp);
23072307
bail!(NonSuccessfulExit);
23082308
}
23092309
Ok(value)
@@ -2324,7 +2324,7 @@ impl WorkerCommandHandler {
23242324
err = err.log_color_error_highlight()
23252325
));
23262326
logln("");
2327-
log_text_view(&WorkerNameHelp);
2327+
log_text_view(&AgentNameHelp);
23282328
bail!(NonSuccessfulExit);
23292329
}
23302330
}
@@ -2391,7 +2391,7 @@ impl WorkerCommandHandler {
23912391
agent_name.0.log_color_error_highlight()
23922392
));
23932393
logln("");
2394-
log_text_view(&WorkerNameHelp);
2394+
log_text_view(&AgentNameHelp);
23952395
bail!(NonSuccessfulExit);
23962396
}
23972397
}

cli/golem-cli/src/model/text/help.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use golem_wasm::analysis::AnalysedType;
2626
use indoc::indoc;
2727
use std::path::PathBuf;
2828

29-
pub struct WorkerNameHelp;
29+
pub struct AgentNameHelp;
3030

31-
impl MessageWithFields for WorkerNameHelp {
31+
impl MessageWithFields for AgentNameHelp {
3232
fn message(&self) -> String {
3333
"Accepted agent name formats:"
3434
.log_color_help_group()

cli/golem-cli/tests/app/build_and_deploy_all.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ async fn build_and_deploy_all_templates_for_lang(language: GuestLanguage) {
7272
let outputs = ctx.cli([cmd::DEPLOY, flag::YES]).await;
7373
assert!(outputs.success_or_dump());
7474

75-
let outputs = ctx.cli([cmd::LIST_AGENT_TYPES, flag::FORMAT, "json"]).await;
75+
let outputs = ctx
76+
.cli([cmd::AGENT_TYPE, cmd::LIST, flag::FORMAT, "json"])
77+
.await;
7678
let deployed_agent_types = outputs
7779
.stdout_json::<Vec<DeployedRegisteredAgentType>>()
7880
.into_iter()

cli/golem-cli/tests/app/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ mod cmd {
6767
pub static NO_ARGS: &[&str] = &[];
6868

6969
pub static AGENT: &str = "agent";
70+
pub static AGENT_TYPE: &str = "agent-type";
7071
pub static BUILD: &str = "build";
7172
pub static COMPLETION: &str = "completion";
7273
pub static COMPONENT: &str = "component";
@@ -75,7 +76,6 @@ mod cmd {
7576
pub static GET: &str = "get";
7677
pub static INVOKE: &str = "invoke";
7778
pub static LIST: &str = "list";
78-
pub static LIST_AGENT_TYPES: &str = "list-agent-types";
7979
pub static NEW: &str = "new";
8080
pub static PLUGIN: &str = "plugin";
8181
pub static REGISTER: &str = "register";

0 commit comments

Comments
 (0)