Implement command builder API for safe command construction#113
Open
Implement command builder API for safe command construction#113
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #34
🚀 Add $.command() builder API as requested in issue #34: - CommandBuilder class with fluent API - Safe argument escaping to prevent shell injection - Pipe configuration support: $.command.stdout(), $.command.exitCode() - Full feature set: stdin, env, cwd, capture, mirror options - Method chaining: .arg(), .env(), .cwd(), .run() - Direct access via CommandBuilder class and command() function ✅ Features: - Exactly matches issue example: $.command("cat", "./file").pipe($.command.stdout("inherit"), $.command.exitCode).run() - Automatic string conversion and shell escaping for safety - Integration with existing ProcessRunner infrastructure - Comprehensive test suite with 21 tests covering safety and functionality - Full documentation with examples and comparison table 🔧 Breaking: Minor version bump to 0.8.0 for new API Fixes #34 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.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.
🚀 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