Skip to content

feat(cli): pass RC_COMMAND_PREFIX environment variable to add-ons (#17) - #26

Merged
colinjlacy merged 1 commit into
runtimeconditions:mainfrom
abhinavkdeval08-design:feat/tell-addons-invoked-prefix-17
Nov 27, 2026
Merged

colinjlacy merged 1 commit into
runtimeconditions:mainfrom
abhinavkdeval08-design:feat/tell-addons-invoked-prefix-17

Conversation

@abhinavkdeval08-design

Copy link
Copy Markdown
Member

Summary

Part of #17.

When rc invokes a language profiler add-on (TypeScript, Java, Python), it now passes RC_COMMAND_PREFIX in the subprocess environment set to the dynamic command path (using cmd.CommandPath(), e.g., rc profile typescript).

This enables add-ons to format their usage diagnostics and command suggestions using the command the user actually ran, rather than naming their standalone binary.

Changes

  1. internal/cli/plugins.go (newLanguageCommand):
    • Injects RC_COMMAND_PREFIX=<cmd.CommandPath()> into process.Spec.Env by appending to os.Environ().
    • Uses cmd.CommandPath() dynamically rather than hardcoded strings, ensuring subcommands, aliases, or binary name variations are accurately reflected.
    • The --version --json metadata probe remains untouched (runs with inherited environment).
  2. internal/cli/plugins_test.go:
    • Added unit test assertions in TestAddOnReceivesItsArgumentsUnchangedAndItsOutputPassesThrough, TestJavaAddOnReceivesItsArgumentsUnchangedAndItsOutputPassesThrough, and TestPythonAddOnReceivesItsArgumentsUnchangedAndItsOutputPassesThrough verifying RC_COMMAND_PREFIX is populated with the correct prefix for TypeScript, Java, and Python add-ons.
  3. docs/language-profilers.md:
    • Documented RC_COMMAND_PREFIX environment variable contract for profiler add-on authors.

Notes for Reviewers

Verification

  • go test -v ./internal/cli -run "^Test(AddOn|JavaAddOn|PythonAddOn)" passed.
  • go vet ./internal/cli/... passed cleanly.

@colinjlacy colinjlacy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great! I love that it doesn't break anything in the profilers if there's a version mismatch between them. If you had gone with a flag or argument, that would have caused interfacing problems. Very nicely done!!! 😁👍

@colinjlacy
colinjlacy merged commit 31fc7da into runtimeconditions:main Nov 27, 2026
4 checks passed
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