Skip to content

Comments

Add support for subcommand extensions#417

Merged
szkiba merged 4 commits intomasterfrom
416-support-for-subcommand-extensions
Feb 17, 2026
Merged

Add support for subcommand extensions#417
szkiba merged 4 commits intomasterfrom
416-support-for-subcommand-extensions

Conversation

@szkiba
Copy link
Contributor

@szkiba szkiba commented Jan 27, 2026

This PR implements native support for k6 subcommand extensions in xk6, enabling developers to build and run subcommand extensions more efficiently.

Changes

This PR adds two key capabilities to xk6:

1. Subcommand Execution (xk6 x)

Introduces the xk6 x command that builds a k6 binary with the extension from the current directory and immediately executes the custom subcommand.

Usage:

# Build and run the subcommand extension
xk6 x <subcommand_name> [flags]

# Example: run the my-tool subcommand with debug flag
xk6 x my-tool --debug

This mirrors the k6 v1.5.0+ syntax (k6 x subcommand) and eliminates the need to manually build and execute binaries during development.

2. Subcommand Extension Scaffolding (xk6 new --type subcommand)

Extends the xk6 new command to generate boilerplate code for subcommand extensions.

Usage:

xk6 new --type subcommand my-extension

The generated template follows the official grafana/xk6-subcommand-example structure, providing a ready-to-use starting point for building custom k6 subcommands.

Motivation

With k6 v1.5.0 introducing subcommand extension support, developers can now create custom CLI commands under the k6 x namespace. However, the development workflow required manual binary builds for each test cycle:

xk6 build --with .
./k6 x my-subcommand

This PR streamlines the workflow to match existing xk6 patterns (like xk6 run for JavaScript extensions), making subcommand extension development more efficient.

Related

Closes #416

Add new 'xk6 x' command that allows developers to execute k6 subcommands
provided by the current directory's extension without manually building
the k6 executable.

Changes:
- Add xCmd() in internal/cmd/x.go to implement the new command
- Create help text in internal/cmd/help/x.md
- Register xCmd in root command
- Refactor run command to use shared runK6Command helper
- Extract runK6Command logic into run_helper.go for reuse
- Update README with xk6 x command documentation

The command builds a temporary k6 binary with the extension and executes
it with the provided subcommand and arguments, streamlining the
development workflow for k6 subcommand extensions.
@szkiba szkiba requested a review from a team as a code owner January 27, 2026 08:30
@szkiba szkiba linked an issue Jan 27, 2026 that may be closed by this pull request
@szkiba szkiba marked this pull request as draft January 27, 2026 08:30
@szkiba szkiba requested a review from andrewslotin January 27, 2026 08:31
@szkiba szkiba marked this pull request as ready for review February 2, 2026 14:26
@szkiba szkiba enabled auto-merge (squash) February 2, 2026 14:26
@szkiba szkiba merged commit 386567b into master Feb 17, 2026
19 checks passed
@szkiba szkiba deleted the 416-support-for-subcommand-extensions branch February 17, 2026 13:52
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.

Support for Subcommand Extensions

2 participants