Move each builtin command to its own package#15
Merged
AlexandreYang merged 1 commit intomainfrom Mar 9, 2026
Merged
Conversation
Co-authored-by: AlexandreYang <49917914+AlexandreYang@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Refactors the
interp/builtinspackage so each builtin command lives in its own sub-package underinterp/builtins/<command>/. The rootbuiltinspackage retains only the shared types (HandlerFunc,CallContext,Result) and registry (Register,Lookup).Motivation
Isolating each builtin into its own package improves modularity: each command has a clear boundary, its own tests, and independent dependencies. It also makes the import allowlist test more maintainable as new builtins are added.
Testing
go build ./interp/...— compiles cleango test ./interp/...— all pass (except pre-existingTestHeadPermissionDeniedwhich fails only when running as root)go test ./tests/— all pass including the updatedTestBuiltinImportAllowlistgoimports/gofmt— no formatting changes neededChecklist
Summary: Each builtin (cat, echo, exit, head, break, continue, true, false) is now a separate Go package that self-registers via
init()+builtins.Register(). Shared logic for break/continue lives inbuiltins/internal/loopctl. The runner wires everything together with blank imports.Changes:
Registerininterp/builtins/builtins.gocat/,echo/,exit/,head/,break/,continue/,true/,false/internal/loopctl/for shared break/continue loop-control logicbuiltins/tests/head/intobuiltins/head/interp/runner_exec.goto triggerinit()registrationTestBuiltinImportAllowlistto walk sub-packages recursively, exempting the parentbuiltinspackage andinternal/importscat.go,echo.go,exit.go,head.go,break_continue.go,true_false.go) andtests/directoryPR by Bits
View session in Datadog
Comment @DataDog to request changes