Skip to main content

CLI

The protoc-gen-go-temporal plugin generates complete command-line interface (CLI) applications using the urfave/cli/v2 (default) or urfave/cli/v3 (optional) framework. These CLIs provide command-line access to all workflow operations including execution, signals, queries, updates, and worker management.

CLI Generation

Each protobuf service with Temporal definitions automatically generates a CLI application with commands for all defined workflows, queries, signals, and updates.

Generated CLI Interface
// CLI Options for configuration
type ExampleCliOptions interface {
WithAfter(func(*cli.Context) error)
WithBefore(func(*cli.Context) error)
WithClientForCommand(func(*cli.Context) (client.Client, error))
WithWorker(func(*cli.Context, client.Client) (worker.Worker, error))
}

// CLI Application constructor
func NewExampleCli(options ...*ExampleCliOptions) (*cli.App, error)

// CLI Command constructor (for embedding)
func NewExampleCliCommand(options ...*ExampleCliOptions) (*cli.Command, error)

CLI Application Setup

Initialize a CLI application with basic client configuration and optional worker setup.

main.go
package main

import (
"log"
"os"

examplev1 "path/to/gen/example/v1"
"go.temporal.io/sdk/client"
)

func main() {
// Create CLI application with client factory
app, err := examplev1.NewExampleCli(
examplev1.NewExampleCliOptions().
WithClient(func(cmd *cli.Context) (client.Client, error) {
return client.Dial(client.Options{})
}),
)
if err != nil {
log.Fatalf("error creating CLI: %v", err)
}

// Run CLI application
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

Command Structure

The generated CLI organizes commands by type and provides comprehensive help text.

example -h
NAME:
example - an example temporal cli

USAGE:
example [global options] command [command options] [arguments...]

COMMANDS:
help, h Shows a list of commands or help for one command
QUERIES:
get-foo-progress GetFooProgress returns the current progress
SIGNALS:
set-foo-progress SetFooProgress updates the current progress
UPDATES:
update-foo-progress UpdateFooProgress modifies and returns progress
WORKFLOWS:
create-foo CreateFoo creates a new foo operation
create-foo-with-set-foo-progress CreateFoo creates a new foo with signal
worker run worker process

GLOBAL OPTIONS:
--address value, -a value temporal server host:port (default: "localhost:7233")
--namespace value, -n value temporal namespace (default: "default")
--help, -h show help

Workflow Execution

Execute workflows synchronously or asynchronously using command-line flags.

Synchronous Execution
# Execute workflow and wait for completion
example create-foo --name "my-foo" --priority 8

# Output:
{
"foo": {
"name": "my-foo",
"status": "FOO_STATUS_READY"
}
}

Signal Operations

Send signals to running workflows using workflow ID and optional run ID.

Send Signal
# Send signal to workflow by ID
example set-foo-progress --workflow-id "create-foo/my-foo" --progress 50.5

# Send signal to specific run
example set-foo-progress \
--workflow-id "create-foo/my-foo" \
--run-id "a1b2c3d4-e5f6-7890-abcd-ef1234567890" \
--progress 75.0

# Success output:
signal sent successfully

Query Operations

Execute queries to retrieve current workflow state.

Execute Query
# Query workflow state
example get-foo-progress --workflow-id "create-foo/my-foo"

# Output:
{
"progress": 75.0,
"status": "FOO_STATUS_CREATING"
}

# Query specific run
example get-foo-progress \
--workflow-id "create-foo/my-foo" \
--run-id "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

Update Operations

Execute workflow updates to modify state and receive return values.

Synchronous Update
# Execute update and wait for completion
example update-foo-progress \
--workflow-id "create-foo/my-foo" \
--progress 100.0

# Output:
{
"progress": 100.0,
"status": "FOO_STATUS_READY"
}

Signal/Update-with-Start

Start workflows with initial signals or updates using combined commands.

Start Workflow with Signal
# Start workflow with initial signal
example create-foo-with-set-foo-progress \
--name "my-foo" \
--priority 5 \
--progress 25.0

# Output (workflow completes with initial signal):
{
"foo": {
"name": "my-foo",
"status": "FOO_STATUS_CREATING"
}
}

Worker Management

Run worker processes to handle workflow and activity execution.

Start Worker
# Start worker process (requires worker configuration in CLI setup)
example worker

# Output:
starting worker...
worker started successfully
press Ctrl+C to stop

Flag Types and Options

The CLI automatically generates typed flags based on protobuf field definitions.

Supported Field Types
message ExampleRequest {
// String fields become --string-field flags
string name = 1;

// Integer fields become --int-field flags
int32 priority = 2;
int64 timeout = 3;

// Float fields become --float-field flags
float progress = 4;
double precision = 5;

// Boolean fields become --bool-field flags
bool enabled = 6;

// Enum fields become --enum-field flags with validation
Status status = 7;

// Duration fields become --duration-field flags (e.g., "1h30m")
google.protobuf.Duration timeout = 8;

// Timestamp fields become --timestamp-field flags (RFC3339)
google.protobuf.Timestamp created_at = 9;

// Repeated fields become --field-name flags (can be specified multiple times)
repeated string tags = 10;

// Message fields become --message-field flags (JSON encoded)
SomeMessage config = 11;

// Map fields become --map-field flags (JSON encoded)
map<string, string> labels = 12;
}

Configuration and Customization

Customize CLI generation using protobuf options and CLI configuration.

CLI Configuration Options
service Example {
// Disable CLI generation for entire service
option (temporal.v1.cli) = {ignore: true};

rpc CreateFoo(CreateFooRequest) returns (CreateFooResponse) {
option (temporal.v1.workflow) = {
cli: {
name: "create" // Override command name
usage: "Create a new foo" // Override command description
aliases: ["c", "new"] // Command aliases
ignore: true // Skip CLI generation for this method
}
};
}
}

message CreateFooRequest {
string name = 1 [(temporal.v1.field).cli = {
name: "foo-name" // Override flag name
usage: "Name of the foo" // Override flag description
aliases: ["n"] // Flag aliases (short flags)
}];
}

Environment Variables

The CLI supports standard Temporal environment variables for configuration.

Supported Environment Variables
# Temporal server configuration
export TEMPORAL_ADDRESS="localhost:7233"
export TEMPORAL_NAMESPACE="my-namespace"

# Task queue configuration
export TEMPORAL_TASK_QUEUE_NAME="my-task-queue"
export TEMPORAL_TASK_QUEUE="my-task-queue"
export TASK_QUEUE_NAME="my-task-queue"
export TASK_QUEUE="my-task-queue"

# Use environment variables
example create-foo --name "test" # Uses env vars for connection

# Override environment variables with flags
example create-foo --name "test" --task-queue "override-queue"

Error Handling and Output

The CLI provides clear error messages and structured output for all operations.

Common Error Scenarios
# Missing required parameters
$ example create-foo
Error: Required flag "name" not set

# Invalid enum values
$ example create-foo --name "test" --status "INVALID_STATUS"
Error: invalid value "INVALID_STATUS" for flag --status

# Connection errors
$ example create-foo --name "test" --address "invalid:7233"
Error: failed to connect to temporal server: connection refused

# Workflow execution errors
$ example create-foo --name "test"
Error: workflow execution failed: some workflow error

# Missing workflow for signals/queries
$ example get-foo-progress --workflow-id "nonexistent"
Error: workflow not found: nonexistent