public function __invoke() {
\WP_CLI::line( 'Type "exit" to close session.' );
+ $this->set_history_file();
+
while ( true ) {
- $line = self::prompt();
+ $line = $this->prompt();
switch ( $line ) {
case '': {
) );
}
- private static function prompt() {
+ private function prompt() {
static $cmd;
if ( !$cmd ) {
- $cmd = self::create_prompt_cmd( 'wp> ', self::get_history_path() );
+ $cmd = self::create_prompt_cmd( 'wp> ', $this->history_file );
}
$fp = popen( $cmd, 'r' );
return '/bin/bash -c ' . escapeshellarg( $cmd );
}
- private static function print_history() {
- $history_file = self::get_history_path();
-
- if ( !is_readable( $history_file ) )
+ private function print_history() {
+ if ( !is_readable( $this->history_file ) )
return;
- $lines = array_filter( explode( "\n", file_get_contents( $history_file ) ) );
+ $lines = array_filter( explode( "\n", file_get_contents( $this->history_file ) ) );
foreach ( $lines as $line ) {
if ( 'history' == $line )
}
}
- private static function get_history_path() {
+ private function set_history_file() {
$data = getcwd() . get_current_user();
- return sys_get_temp_dir() . '/wp-cli-history-' . md5( $data );
+ $this->history_file = sys_get_temp_dir() . '/wp-cli-history-' . md5( $data );
}
private static function starts_with( $tokens, $line ) {