Add structured Command execution with composition and redirects#2
Add structured Command execution with composition and redirects#2
Conversation
- Add Utopia\Command class for building shell commands safely - Support per-argument validation using Utopia\Servers\Validator or callables - Add toArray() for safe argv execution and toString() for escaped shell strings - Update Console::execute() to accept Command|array|string - Fix exit code handling for Command/array execution - Add tests for Command functionality - Update README with Command usage examples - Add utopia-php/servers dependency for Validator class
Greptile SummaryThis PR introduces a Confidence Score: 5/5Safe to merge; all previously flagged issues (PHP version constraint, The only remaining finding is a P2 visibility concern ( src/Command.php — Important Files Changed
Reviews (5): Last reviewed commit: "Refine command composition API and redir..." | Re-trigger Greptile |
- Remove bool from union types to avoid confusing error messages - Update PHP version constraint to >=8.2 (required by transitive dependency) - Implement Stringable interface with __toString() method
|
@greptile-apps Thanks for the review! I've addressed all three comments:
All tests pass and PHPStan shows no errors. Could you please take another look? |
- Remove PHP 8.1 from test matrix (now requires PHP 8.2+) - Regenerate composer.lock to sync with updated PHP version constraint
- Fix Console::execute() to use proc_get_status()['exitcode'] instead of proc_close() return value, which can be -1 on some systems - Regenerate composer.lock using PHP 8.2 to ensure dependencies are compatible with minimum PHP version
|
@greptile-apps We've pushed fixes for the CI failures:
All tests pass locally now. Could you please take another look? |
|
@greptile-apps We pushed a larger API refinement on top of the original Highlights:
All checks are passing locally:
|
Summary
Utopia\Commandvalue object for structured command building inConsole::execute()add()API with explicitflag(),option(), andargument()methods backed by per-value validationCommand::pipe(),Command::and(),Command::or(),Command::group(),Command::redirectStdout(),Command::appendStdout(), andCommand::redirectInput()stringandarraycommand execution paths while making structured commands the documented defaultCommand API
flag(),option(), andargument()option()andargument()default toText(0)validation while still allowing custom validators or callablestoArray()is now limited to plain commands and throws on composed/grouped/redirected expressionsConsole updates
Console::execute()acceptsCommand|array|stringCommandinstances are converted to argv arrays beforeproc_open()Commandexpressions are converted to shell strings before execution0Dependency and platform changes
utopia-php/serversvalidator dependency to the directutopia-php/validatorspackage>=8.0composer.lockfor the updated dependency graphDocumentation
CommandAPITesting
composer testcomposer lintcomposer check