Skip to content

Delegate help and completion to extensions when applicable - #1137

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

Delegate help and completion to extensions when applicable#1137
jeri-temporal wants to merge 4 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Temporal CLI’s extension-dispatch logic so that help and Cobra shell completion (__complete / __completeNoDesc) can be delegated to matching extensions, and so extensions appear in shell completion results at the root command.

Changes:

  • Teach tryExecuteExtension to rewrite/delegate help and shell completion requests to matching extensions when applicable.
  • Register discovered extensions as placeholder Cobra commands during shell completion so they show up in completion candidates.
  • Update extension discovery to return executable paths and add/extend unit tests around completion and built-in command shadowing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
internal/temporalcli/commands.help.go Enhances extension placeholder registration to support nested extension paths and show executable locations in help/completion.
internal/temporalcli/commands.go Registers extension placeholder commands during __complete when no extension handled the request.
internal/temporalcli/commands.extension.go Adds delegated-command splitting for help/completion, adjusts extension execution args, and changes extension discovery to return executable paths.
internal/temporalcli/commands.extension_test.go Adds tests for extension visibility in completion and ensures built-ins (like completion) are not shadowed.
Suppressed comments (1)

internal/temporalcli/commands.extension.go:133

  • splitDelegatedCommands always strips the leading help token, which makes tcmd.Command.Find() run against the remaining args. For invocations like temporal help --all, that causes --all (a help-command flag) to be parsed against the root command, leading to an "unknown flag: --all" error and breaking built-in help.
	if args[0] == "help" {
		// "help __complete" never delegates, whatever comes after, so we can just mark "help" as delegatable and see what matches
		return args[:1], args[1:]
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/temporalcli/commands.extension.go Outdated
Comment thread internal/temporalcli/commands.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

2 participants