Skip to content

Commit

Permalink
Merge pull request #77 from the-events-calendar/feat/cli-bash
Browse files Browse the repository at this point in the history
Open a shell in the wp-cli container on tric cli
  • Loading branch information
lucatume authored Mar 5, 2021
2 parents 65aa1ef + 972d2bf commit 1bae9ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.26] - 2021-03-05
### Changed
- Allow opening a shell in the `cli` service to run wp-cli commands just using `tric cli`.

## [0.5.25] - 2021-03-02
### Changed
- Set `COMPOSER_HTACCESS_PROTECT=0` explicitly in the `docker-compose` configuration file to avoid an `.htaccess`
Expand Down
9 changes: 6 additions & 3 deletions src/commands/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
* wp-cli already comes with a `shell` command that will open a PHP shell, same as `php -a`, in it.
* As much as it would be ideal to use the `shell` sub-command to open a shell... we cannot use the `shell` word.
*/
$open_bash_shell = reset( $command ) === 'bash';
$cli_command = reset( $command );
// If the command is `bash` or is empty, then open a shell in the `cli` service.
$open_bash_shell = empty( $cli_command ) || $cli_command === 'bash';
if ( ! $open_bash_shell ) {
$status = tric_realtime()( cli_command( $command ) );
} else {
// What user ID are we running this as?
$user = getenv( 'DOCKER_RUN_UID' );
// Do not run the wp-cli container as `root` to avoid a number of file mode issues, run as `www-data` instead.
$user = empty( $user ) ? 'www-data' : $user;
$status = tric_realtime()( [ 'run', '--rm', "--user={$user}", '--entrypoint', 'bash', 'cli' ] );
}

$status = tric_realtime()( [ 'run', '-e PS1="wp-cli » "', '--rm', "--user={$user}", '--entrypoint', 'bash', 'cli' ] );

}
exit( $status );
2 changes: 1 addition & 1 deletion tric
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $args = args( [
] );

$cli_name = basename( $argv[0] );
const CLI_VERSION = '0.5.25';
const CLI_VERSION = '0.5.26';

$cli_header = implode( ' - ', [
light_cyan( $cli_name ) . ' version ' . light_cyan( CLI_VERSION ),
Expand Down

0 comments on commit 1bae9ad

Please sign in to comment.