Repository navigation
feat: implement pipes, variable expansion and declare/export/unset builtins - #8
Merged
Merged
Conversation
…g logic - Add ProcessBuilderFactory with build(), configureRedirect(), configureOutput() - Update ExternalCommand to use ProcessBuilderFactory - Remove duplicate buildProcessArgs and configureRedirect from ExternalCommand
- Rename tokenize() logic to tokenizeStage() for per-stage parsing - Add splitByPipe() to split input by | respecting single and double quotes - Move background & detection from extractRedirect to tokenize() - Remove background flag from ParseResult, now carried by PipelineResult - Return PipelineResult from tokenize() containing all stages and background flag
- Execute single stage directly via CommandRegistry - Chain external commands via ProcessBuilder PIPE redirects - Support builtin commands in pipeline via System.out/in capture - Feed previous stage output into next via daemon feeder thread - Support background pipeline execution
- Add variables map to Environment for local variable storage - Add setVariable(), getVariable(), unsetVariable() methods - getVariable() checks local variables first, then system env - Return unmodifiable view of variables map via getVariables() - Add lastExitCode field to track exit code of last command - Add lastBackgroundPid field to track PID of last background job - Expose via getters and setters for use in variable expansion
- Add expandVariables() called before tokenizing each stage
- Support $VAR and ${VAR} syntax expanding from Environment
- Support $? expanding to last command exit code
- Support $$ expanding to current shell PID
- Support $! expanding to last background job PID
- Skip expansion inside single quotes
- Unexpanded variables resolve to empty string
- Pass Environment into Tokenizer constructor
- Add DeclareBuiltin to set variables via declare VAR=value - List all variables with declare output format - Print single variable with declare VAR - Register as environment-dependent builtin in BuiltinFactory
- Add ExportBuiltin to set variables via export VAR=value - List all exported variables with export output format - Register as environment-dependent builtin in BuiltinFactory
- Add UnsetBuiltin to remove variables from Environment - Support multiple arguments to unset several variables at once - Register as environment-dependent builtin in BuiltinFactory
- Detect VAR=value pattern at start of handleInput - Set variable in Environment without executing as command - Support standard shell assignment syntax
- Capture process exit code and store in Environment.lastExitCode - Store background process PID in Environment.lastBackgroundPid - Makes $? and $! expansion work correctly after command execution
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.
Summary
Implements pipeline execution with
|operator, variable expansion, and variable management builtins (declare,export,unset).Changes
Pipeline Execution
PipelineResultrecord to carry pipeline stages and background flagProcessBuilderFactoryto centralize process building and redirect configuration, eliminating duplication betweenExternalCommandandPipelinePipelineexecutor supporting single and multi-stage pipelinesSystem.out/incaptureProcessBuilderPIPE redirectsTokenizerto split input by|respecting quotesPipelineResultfromtokenizer.tokenize()instead ofParseResultVariable Expansion
EnvironmentwithsetVariable,getVariable,unsetVariablemethodslastExitCodeandlastBackgroundPidtracking toEnvironmentexpandVariables()inTokenizersupporting:$VARand${VAR}syntax$?last exit code$$current shell PID$!last background job PIDVAR=valueassignment syntax inShell.handleInputExternalCommandto track exit code and background PIDNew Builtins
declare— set and list variablesexport— export variables to environmentunset— remove variablesTesting
Manually verified:
echo hello | catpipes output correctlydir | findstr ".java"filters output on Windowsecho hello | cat | catchains multiple pipesMY_VAR=hello && echo $MY_VARexpands variablesecho $PATHexpands system environment variablesecho $?shows last exit codeecho $$shows shell PIDdeclare MY_VAR=hellosets variableexport MY_VAR=helloexports variableunset MY_VARremoves variable