Updating i18n shell to start using new OptionParser class.

Removing more dead attributes from Shell. Making Shell::$name the name used to invoke the shell, not the classname.  This makes it similar to other objects with names.
This commit is contained in:
mark_story 2010-10-10 00:59:45 -04:00
parent 2a2428a694
commit 41b8affa82
3 changed files with 23 additions and 34 deletions

View file

@ -65,7 +65,7 @@ class I18nShell extends Shell {
*
*/
public function main() {
$this->out(__('I18n Shell'));
$this->out(__('<info>I18n Shell</info>'));
$this->hr();
$this->out(__('[E]xtract POT file from sources'));
$this->out(__('[I]nitialize i18n database table'));
@ -81,7 +81,7 @@ class I18nShell extends Shell {
$this->initdb();
break;
case 'h':
$this->help();
$this->out($this->OptionParser->help());
break;
case 'q':
exit(0);
@ -102,6 +102,16 @@ class I18nShell extends Shell {
$this->Dispatch->dispatch();
}
/**
* Get and configure the Option parser
*
* @return ConsoleOptionParser
*/
protected function _getOptionParser() {
$parser = parent::_getOptionParser();
return $parser->description(__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.'));
}
/**
* Show help screen.
*

View file

@ -83,14 +83,6 @@ class Shell extends Object {
*/
public $shell = null;
/**
* The class name of the shell that was invoked.
*
* @var string
* @access public
*/
public $className = null;
/**
* The command called if public methods are available.
*
@ -107,14 +99,6 @@ class Shell extends Object {
*/
public $name = null;
/**
* An alias for the shell
*
* @var string
* @access public
*/
public $alias = null;
/**
* Contains tasks to load and instantiate
*
@ -179,22 +163,18 @@ class Shell extends Object {
*
*/
function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) {
$vars = array('params', 'args', 'shell', 'shellCommand' => 'command', 'shellPaths');
$vars = array('shell', 'shellCommand' => 'command', 'shellPaths');
foreach ($vars as $key => $var) {
if (is_string($key)) {
$this->{$var} =& $dispatch->{$key};
$this->{$var} = $dispatch->{$key};
} else {
$this->{$var} =& $dispatch->{$var};
$this->{$var} = $dispatch->{$var};
}
}
if ($this->name == null) {
$this->name = get_class($this);
}
if ($this->alias == null) {
$this->alias = $this->name;
$this->name = Inflector::underscore(str_replace('Shell', '', get_class($this)));
}
$this->Dispatch =& $dispatch;
@ -243,8 +223,8 @@ class Shell extends Object {
$this->out();
$this->out('<info>Welcome to CakePHP v' . Configure::version() . ' Console</info>');
$this->hr();
$this->out('App : '. $this->params['app']);
$this->out('Path: '. $this->params['working']);
$this->out('App : '. $this->Dispatch->params['app']);
$this->out('Path: '. $this->Dispatch->params['working']);
$this->hr();
}
@ -343,21 +323,20 @@ class Shell extends Object {
if ($isTask || $isMethod) {
array_shift($argv);
}
$this->OptionParser = $this->_getOptionParser();
list($this->params, $this->args) = $this->OptionParser->parse($argv);
if ($isTask || $isMethod || $isMain) {
$this->startup();
}
if ($isTask) {
$command = Inflector::camelize($command);
return $this->{$command}->runCommand('execute', $argv);
}
$this->OptionParser = $this->_getOptionParser();
list($this->params, $this->args) = $this->OptionParser->parse($argv);
if (isset($this->params['help'])) {
return $this->out($this->OptionParser->help());
}
if ($isMethod) {
return $this->{$command}();
}

View file

@ -260,7 +260,7 @@ class ShellDispatcher {
$this->shellClass = $this->shellName . 'Shell';
$Shell = $this->_getShell($plugin);
$command = null;
if (isset($this->args[0])) {
$command = $this->args[0];