Skip to content

Delegate help and completion to extensions when applicable#1137

Open
jeri-temporal wants to merge 2 commits into
temporalio:mainfrom
jeri-temporal:main
Open

Delegate help and completion to extensions when applicable#1137
jeri-temporal wants to merge 2 commits into
temporalio:mainfrom
jeri-temporal:main

Conversation

@jeri-temporal

Copy link
Copy Markdown
Contributor

Shell completion always sets __complete as the first argument, so to
delegate to extensions, temporal __complete cloud n needs to be
rewritten as temporal-cloud __complete n. help can be invoked the
same way

Related issues

CLDDX-150

What changed?

  • tryExecuteExtension delegates help and shell completion to extensions that match the remaining arguments
  • extensions are registered during shell completion, so "temporal " will show them

Checklist

Design

  • This feature does not depend on Cloud-only APIs or behavior (it works against an OSS server)

Tests

  • Added unit test(s) (func TestXxx) where applicable

Manual tests

Setup
Install at least one extension, like the cloud cli (brew install temporalio/prerelease/temporal-cloud on Mac or Linux with homebrew installed)

Happy path

$ temporal <TAB>
activity    -- Operate on Activity Executions
batch       -- Manage running batch jobs
cloud       -- An extension command located at /opt/homebrew/bin/temporal-cloud
completion  -- Generate the autocompletion script for the specified shell
config      -- Manage config files (EXPERIMENTAL)
env         -- Manage environments
help        -- Help about any command
nexus       -- Start, list, and operate on Nexus Operations
operator    -- Manage Temporal deployments
schedule    -- Perform operations on Schedules
server      -- Run Temporal Server
task-queue  -- Manage Task Queues
worker      -- Read or update Worker state
workflow    -- Start, list, and operate on Workflows

$ temporal cl<TAB>
temporal cloud

$ temporal cloud <TAB>
account          -- Manage Temporal Cloud account
apikey           -- Manage Temporal Cloud API keys
async-operation  -- Manage async operations
connectivity     -- Manage Temporal Cloud connectivity rules
custom-role      -- [Experimental] Manage Temporal Cloud custom roles
help             -- Help about any command
login            -- Authenticate with Temporal Cloud
logout           -- Clear Temporal Cloud authentication credentials
namespace        -- Manage Temporal Cloud namespaces
nexus            -- Manage Temporal Cloud Nexus Operations
region           -- Manage Temporal Cloud regions
service-account  -- Manage Temporal Cloud service accounts
user             -- Manage Temporal Cloud users
user-group       -- Manage Temporal Cloud user groups
whoami           -- Display the current authenticated identity
$ temporal help --all
...
Available Commands:
  activity    Operate on Activity Executions
  batch       Manage running batch jobs
  cloud       An extension command located at /opt/homebrew/bin/temporal-cloud
  completion  Generate the autocompletion script for the specified shell
  config      Manage config files (EXPERIMENTAL)
  env         Manage environments
  help        Help about any command
  nexus       Start, list, and operate on Nexus Operations
  operator    Manage Temporal deployments
  schedule    Perform operations on Schedules
  server      Run Temporal Server
  task-queue  Manage Task Queues
  worker      Read or update Worker state
  workflow    Start, list, and operate on Workflows
...

temporal help cloud
The Temporal Cloud CLI provides commands for managing and operating Temporal Cloud resources,
including namespaces, users, and account settings.

Example:

temporal cloud namespace get --namespace my-namespace.my-account

Usage:
  temporal cloud [command]

Available Commands:
  account         Manage Temporal Cloud account
  apikey          Manage Temporal Cloud API keys
  async-operation Manage async operations
  connectivity    Manage Temporal Cloud connectivity rules
  custom-role     [Experimental] Manage Temporal Cloud custom roles
  help            Help about any command
  login           Authenticate with Temporal Cloud
  logout          Clear Temporal Cloud authentication credentials
  namespace       Manage Temporal Cloud namespaces
  nexus           Manage Temporal Cloud Nexus Operations
  region          Manage Temporal Cloud regions
  service-account Manage Temporal Cloud service accounts
  user            Manage Temporal Cloud users
  user-group      Manage Temporal Cloud user groups
  whoami          Display the current authenticated identity

Error case

temporal z<TAB>

(no completions shown)

Behavior remains unchanged when an unknown argument is passed to temporal help:

$ temporal help zzz
The Temporal CLI manages, monitors, and debugs Temporal apps. It lets you run
a local Temporal Service, start Workflow Executions, pass messages to running
Workflows, inspect state, and more.
...

Shell completion always sets __complete as the first argument, so to
delegate to extensions, `temporal __complete cloud n` needs to be
rewritten as `temporal-cloud __complete n`. `help` can be invoked the
same way
@jeri-temporal
jeri-temporal requested a review from a team as a code owner July 23, 2026 23:26
// the current command's path in the hierarchy.
// so they appear in shell completion and the default help output. It filters extensions
// based on the current command's path in the hierarchy.
func registerExtensionCommands(cmd *cobra.Command) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is used for shell completion as well, it feels like it probably belongs in commands.extension.go, but I didn't want to move it at the same time as making modifications to its behavior. If you agree, I'm happy to move it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant