Skip to content

Commit 29513bd

Browse files
authored
Merge branch 'develop-v4' into move-compatibility-of-args
2 parents a343a6c + e575ef4 commit 29513bd

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

php/class-ee.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,20 @@ public static function remove_deferred_addition( $name ) {
480480
}
481481

482482
/**
483-
* Display informational message without prefix, and ignore `--quiet`.
483+
* Display informational message without prefix.
484484
*
485-
* Message is written to STDOUT. `EE::log()` is typically recommended;
486-
* `EE::line()` is included for historical compat.
485+
* Should only be used for displaying sensitive info which should be skipped from log file.
486+
* `EE::log()` is typically recommended for everything else.
487487
*
488-
* @access public
488+
* @access public
489489
* @category Output
490490
*
491491
* @param string $message Message to display to the end user.
492+
*
492493
* @return null
493494
*/
494495
public static function line( $message = '' ) {
495-
echo $message . "\n";
496+
self::$logger->info( $message );
496497
}
497498

498499
/**
@@ -818,19 +819,21 @@ public static function error_to_string( $errors ) {
818819
* @access public
819820
* @category Execution
820821
*
821-
* @param string $command External process to launch.
822+
* @param string $command External process to launch.
822823
* @param boolean $exit_on_error Whether to exit if the command returns an elevated return code.
823824
* @param boolean $return_detailed Whether to return an exit status (default) or detailed execution results.
824-
* @param array $env Environment variables to set when running the command.
825-
* @param string $cwd Directory to execute the command in.
825+
* @param array $obfuscate Parts of the command that need to be obfuscated.
826+
* @param array $env Environment variables to set when running the command.
827+
* @param string $cwd Directory to execute the command in.
826828
*
827829
* @return int|ProcessRun The command exit status, or a ProcessRun object for full details.
828830
*/
829-
public static function launch( $command, $exit_on_error = false, $return_detailed = true, $env = null, $cwd = null ) {
831+
public static function launch( $command, $exit_on_error = false, $return_detailed = true, $obfuscate = [], $env = null, $cwd = null ) {
830832
Utils\check_proc_available( 'launch' );
831833

834+
$command_to_log = empty( $obfuscate ) ? $command : str_replace( $obfuscate, '******', $command );
832835
self::debug( '-----------------------' );
833-
self::debug( "COMMAND: $command" );
836+
self::debug( "COMMAND: $command_to_log" );
834837

835838
$proc = Process::create( $command, $cwd, $env );
836839
$results = $proc->run();
@@ -858,18 +861,20 @@ public static function launch( $command, $exit_on_error = false, $return_detaile
858861
* @access public
859862
* @category Execution
860863
*
861-
* @param string $command External process to launch.
862-
* @param bool $echo_stdout Print stdout to terminal. Default false.
863-
* @param bool $echo_stderr Print stderr to terminal. Default false.
864+
* @param string $command External process to launch.
865+
* @param bool $echo_stdout Print stdout to terminal. Default false.
866+
* @param bool $echo_stderr Print stderr to terminal. Default false.
867+
* @param array $obfuscate Parts of the command that need to be obfuscated.
864868
* @param boolean $exit_on_error Exit if the command returns an elevated return code with stderr.
865869
*
866870
* @return bool True if executed successfully. False if failed.
867871
*/
868-
public static function exec( $command, $echo_stdout = false, $echo_stderr = false, $exit_on_error = false ) {
872+
public static function exec( $command, $echo_stdout = false, $echo_stderr = false, $obfuscate = [], $exit_on_error = false ) {
869873
Utils\check_proc_available( 'exec' );
870874

875+
$command_to_log = empty( $obfuscate ) ? $command : str_replace( $obfuscate, '******', $command );
871876
self::debug( '-----------------------' );
872-
self::debug( "COMMAND: $command" );
877+
self::debug( "COMMAND: $command_to_log" );
873878

874879
$proc = Process::create( $command, null, null );
875880
$results = $proc->run();

php/utils.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,19 +1508,25 @@ function get_type( $assoc_args, $arg_types, $default = false ) {
15081508
* # +------+--------+
15091509
* ```
15101510
*
1511-
* @param array $items An array of items to output.
1511+
* @param array $items An array of items to output.
1512+
* @param bool $log_data To log table in file or not.
15121513
*
15131514
*/
1514-
function format_table( $items ) {
1515+
function format_table( $items, $log_in_file = false ) {
15151516
$item_table = new \cli\Table();
15161517
$item_table->setRows( $items );
15171518
$item_table->setRenderer( new \cli\table\Ascii() );
15181519
$lines = array_slice( $item_table->getDisplayLines(), 3 );
15191520
array_pop( $lines );
15201521
$delem = $item_table->getDisplayLines()[0];
15211522
foreach ( $lines as $line ) {
1522-
\EE::log( $delem );
1523-
\EE::log( $line );
1523+
if ( $log_in_file ) {
1524+
\EE::log( $delem );
1525+
\EE::log( $line );
1526+
} else {
1527+
\EE::line( $delem );
1528+
\EE::line( $line );
1529+
}
15241530
}
15251531
\EE::log( $delem );
15261532
}

0 commit comments

Comments
 (0)