Commit bfb9aa84 by Qiang Xue

WIP

parent 11a4d6de
...@@ -45,7 +45,7 @@ class GenerateController extends Controller ...@@ -45,7 +45,7 @@ class GenerateController extends Controller
public function __get($name) public function __get($name)
{ {
return isset($this->_options[$name]) ? $this->_options[$name] : null; return isset($this->_options[$name]) ? $this->_options[$name] : null;
// todo: should determine which options are valid
if ($this->action) { if ($this->action) {
$options = $this->options($this->action->id); $options = $this->options($this->action->id);
if (in_array($name, $options)) { if (in_array($name, $options)) {
...@@ -67,6 +67,7 @@ class GenerateController extends Controller ...@@ -67,6 +67,7 @@ class GenerateController extends Controller
{ {
$this->_options[$name] = $value; $this->_options[$name] = $value;
return; return;
// todo: should determine which options are valid
if ($this->action) { if ($this->action) {
$options = $this->options($this->action->id); $options = $this->options($this->action->id);
if (in_array($name, $options)) { if (in_array($name, $options)) {
...@@ -122,9 +123,11 @@ class GenerateController extends Controller ...@@ -122,9 +123,11 @@ class GenerateController extends Controller
public function options($id) public function options($id)
{ {
if (isset($this->generators[$id])) { if (isset($this->generators[$id])) {
$attributes = $this->generators[$id]->attributes;
unset($attributes['templates']);
return array_merge( return array_merge(
parent::options($id), parent::options($id),
array_keys($this->generators[$id]->attributes) array_keys($attributes)
); );
} else { } else {
return parent::options($id); return parent::options($id);
...@@ -146,7 +149,8 @@ class GenerateController extends Controller ...@@ -146,7 +149,8 @@ class GenerateController extends Controller
public function getActionHelp($action) public function getActionHelp($action)
{ {
/** @var $action Action */ /** @var $action Action */
return $action->generator->getDescription(); $description = $action->generator->getDescription();
return wordwrap(preg_replace('/\s+/', ' ', $description));
} }
/** /**
...@@ -164,17 +168,27 @@ class GenerateController extends Controller ...@@ -164,17 +168,27 @@ class GenerateController extends Controller
{ {
/** @var $action Action */ /** @var $action Action */
$attributes = $action->generator->attributes; $attributes = $action->generator->attributes;
unset($attributes['templates']);
$hints = $action->generator->hints(); $hints = $action->generator->hints();
$options = []; $options = [];
foreach ($attributes as $name => $value) { foreach ($attributes as $name => $value) {
$type = gettype($value);
$options[$name] = [ $options[$name] = [
'type' => 'string', 'type' => $type === 'NULL' ? 'string' : $type,
'required' => $action->generator->isAttributeRequired($name),
'default' => $value, 'default' => $value,
'comment' => isset($hints[$name]) ? $hints[$name] : '', 'comment' => isset($hints[$name]) ? $this->formatHint($hints[$name]) : '',
]; ];
} }
return $options; return $options;
} }
protected function formatHint($hint)
{
$hint = preg_replace('%<code>(.*?)</code>%', '\1', $hint);
$hint = preg_replace('/\s+/', ' ', $hint);
return wordwrap($hint);
}
} }
...@@ -9,7 +9,6 @@ namespace yii\console\controllers; ...@@ -9,7 +9,6 @@ namespace yii\console\controllers;
use Yii; use Yii;
use yii\base\Application; use yii\base\Application;
use yii\base\InlineAction;
use yii\console\Controller; use yii\console\Controller;
use yii\console\Exception; use yii\console\Exception;
use yii\helpers\Console; use yii\helpers\Console;
...@@ -302,7 +301,7 @@ class HelpController extends Controller ...@@ -302,7 +301,7 @@ class HelpController extends Controller
if (!empty($options)) { if (!empty($options)) {
$this->stdout("\nOPTIONS\n\n", Console::BOLD); $this->stdout("\nOPTIONS\n\n", Console::BOLD);
foreach ($options as $name => $option) { foreach ($options as $name => $option) {
echo $this->formatOptionHelp($this->ansiFormat('--' . $name, Console::FG_RED), false, $option['type'], $option['default'], $option['comment']) . "\n\n"; echo $this->formatOptionHelp($this->ansiFormat('--' . $name, Console::FG_RED), !empty($option['required']), $option['type'], $option['default'], $option['comment']) . "\n\n";
} }
} }
} }
...@@ -329,7 +328,12 @@ class HelpController extends Controller ...@@ -329,7 +328,12 @@ class HelpController extends Controller
// show as integer to avoid confusion // show as integer to avoid confusion
$defaultValue = (int) $defaultValue; $defaultValue = (int) $defaultValue;
} }
$doc = "$type (defaults to " . var_export($defaultValue, true) . ")"; if (is_string($defaultValue)) {
$defaultValue = "'" . $defaultValue . "'";
} else {
$defaultValue = var_export($defaultValue, true);
}
$doc = "$type (defaults to " . $defaultValue . ")";
} elseif (trim($type) !== '') { } elseif (trim($type) !== '') {
$doc = $type; $doc = $type;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment