diff --git a/changelog.md b/changelog.md index 238b84b..25fb005 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.4] - 2020-08-18 +### Changed + +- Add support for multiple commands in the `target` command to allow running a set of commands on a set of targets. + ## [0.5.3] - 2020-08-13 ### Changed diff --git a/src/commands/target.php b/src/commands/target.php index 1d637ad..3ca8709 100644 --- a/src/commands/target.php +++ b/src/commands/target.php @@ -8,7 +8,7 @@ namespace Tribe\Test; if ( $is_help ) { - echo "Runs a command on a set of targets.\n"; + echo "Runs a set of commands on a set of targets.\n"; echo PHP_EOL; echo colorize( "usage: tric target\n" ); @@ -17,33 +17,35 @@ $targets = []; do { - $last_target = ask( 'Target (return when done): ', null ); + $last_target = ask( 'Target (return when done):', null ); if ( $last_target && ensure_valid_target( $last_target, false ) ) { $targets[] = $last_target; - } else { - continue; } -} while ( $last_target ); +} while ( ! empty( $last_target ) ); $targets = array_unique( $targets ); +$command_lines = []; + echo yellow( "\nTargets: " ) . implode( ', ', $targets ) . "\n\n"; // Allow users to enter a command prefixing it with `tric` or not. do { - $command_line = trim( - preg_replace( '/^\\s*tric/', '', ask( 'Command: ' ) + $last_command_line = trim( + preg_replace( '/^\\s*tric/', '', ask( 'Command (return when done):', null ) ) ); -} while ( ! $command_line ); + if ( ! empty( $last_command_line ) ) { + $command_lines[] = $last_command_line; + } +} while ( ! empty( $last_command_line ) ); -echo "\n"; +echo yellow( "\nTargets: " ) . implode( ', ', $command_lines ) . "\n\n"; if ( preg_match( '/^n/i', ask( colorize( sprintf( - "Are you sure you want to run %s on %s?", - $command_line, + "Are you sure you want to run these commands on %s?", implode( ', ', $targets ) ) ), @@ -54,7 +56,14 @@ return; } -$command = preg_split( '/\\s/', $command_line ); -$base_command = array_shift( $command ); +foreach ( $command_lines as $command_line ) { + $command = preg_split( '/\\s/', $command_line ); + $base_command = array_shift( $command ); + $status = execute_command_pool( build_targets_command_pool( $targets, $base_command, $command, [ 'common' ] ) ); + if ( 0 !== (int) $status ) { + // If any previous command fails, then exit. + exit( $status ); + } +} +exit( $status ); -exit( execute_command_pool( build_targets_command_pool( $targets, $base_command, $command, [ 'common' ] ) ) ); diff --git a/tric b/tric index 8d711d1..b9ee23f 100755 --- a/tric +++ b/tric @@ -25,7 +25,7 @@ $args = args( [ ] ); $cli_name = basename( $argv[0] ); -const CLI_VERSION = '0.5.3'; +const CLI_VERSION = '0.5.4'; $cli_header = implode( ' - ', [ light_cyan( $cli_name ) . ' version ' . light_cyan( CLI_VERSION ), @@ -53,7 +53,7 @@ Available commands: init Initializes a plugin for use in tric. composer Runs a Composer command in the stack. npm Runs an npm command in the stack. -target Runs a command on a set of targets. +target Runs a set of commands on a set of targets. xdebug Activates and deactivates XDebug in the stack, returns the current XDebug status or sets its values. airplane-mode Activates or deactivates the airplane-mode plugin. cache Activates and deactivates object cache support, returns the current object cache status.