Implement command builder API for safe command construction #113
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.
🚀 Command Builder API Implementation
This PR implements the command builder API requested in issue #34, providing a safe, injection-free way to construct and execute commands.
📋 Issue Reference
Fixes #34
✨ New Features
$.command() Builder API
Implements the exact API requested in the issue:
Key Capabilities
📝 Implementation Details
Core Components
API Methods
.arg(...args)- Add arguments.stdin(input)- Configure stdin.stdout(mode)- Configure stdout handling.stderr(mode)- Configure stderr handling.env(vars)- Set environment variables.cwd(dir)- Set working directory.capture(bool)- Enable/disable capture.mirror(bool)- Enable/disable mirroring.pipe(...configs)- Apply pipe configurations.run(options)- Execute and return ProcessRunner🧪 Testing
Comprehensive test suite with 21 tests:
📚 Examples
Basic Usage
Method Chaining
Safety Demonstration
🔧 Changes Made
Core Implementation (
src/$.mjs):CommandBuilderclass with full APIcommand()factory functionDocumentation (
README.md):Testing (
tests/command-builder.test.mjs):Examples:
examples/command-builder-demo.mjs- Complete demo of all featuresexamples/test-command-builder-result.mjs- Result structure analysis📊 Version Update
Bumped version to 0.8.0 as this adds a significant new API feature.
🆚 Comparison with Other Libraries
command-stream is now the only JavaScript shell library with:
$`cmd`)Other libraries like execa, Bun.$, zx, and ShellJS lack this secure command construction pattern.
Ready for review! The implementation matches the issue requirements exactly while providing comprehensive safety features and extensive testing.
🤖 Generated with Claude Code