econsolecommand EConsoleCommand makes Yii console commands more interactive and user friendly.

  1. Requirements
  2. Usage

EConsoleCommand implements some functionality makes Yii console commands more interactive and user friendly.

The extension consist on the EConsoleCommand class, and implements methods to prompt data to the user by input, such as promptString, promptNumber, promptFloat, also boolean confirmations with confirm and several methods to print colorized text on Unix or GNU/Linux terminals, such as Bash.

The extension also takes care to detect when not use colors in the terminal, for example when you redirect the output to the file or when you are using Windows terminal.

Requirements

This extension requires Yii 1.1.x.

Usage

You must save the EConsoleCommand.php file in an accessible directory for your console commands, for example, you can save the file in the extensions directory and configure your console application to auto-import this directory:

'import'=>array(
    'application.extensions.*',
)

Also, you can use Yii::import() method to manually import the file.

Then, you must extend your console command with EConsoleCommand class. In this example, we create a command that prompt a directory to the user, using "/home/ftp" as default if the user put an empty string, print the path using a cyan color for the foreground and finally print a error (a red text):

class MyConsoleCommand extends EConsoleCommand
{
	public function actionIndex()
	{
		$path = $this->promptString('Please introduce the download directory', '/home/ftp');
		$this->printlnColor($path, self::FGB_CYAN);
		$this->printlnError('This is an error text');
	}
}

The extension auto-detect when you are redirecting the output to a file or another command using posix_isatty function, disabling colorize, if you're having problems with this detection you can force to disable or enable text colorizing using disableColors and enableColors methods respectively.

3 0
5 followers
707 downloads
Yii Version: 1.1
License: MIT
Category: Console
Developed by: eor
Created on: Sep 8, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions