Commit bfb9aa84 by Qiang Xue

WIP

parent 11a4d6de
......@@ -45,7 +45,7 @@ class GenerateController extends Controller
public function __get($name)
{
return isset($this->_options[$name]) ? $this->_options[$name] : null;
// todo: should determine which options are valid
if ($this->action) {
$options = $this->options($this->action->id);
if (in_array($name, $options)) {
......@@ -67,6 +67,7 @@ class GenerateController extends Controller
{
$this->_options[$name] = $value;
return;
// todo: should determine which options are valid
if ($this->action) {
$options = $this->options($this->action->id);
if (in_array($name, $options)) {
......@@ -122,9 +123,11 @@ class GenerateController extends Controller
public function options($id)
{
if (isset($this->generators[$id])) {
$attributes = $this->generators[$id]->attributes;
unset($attributes['templates']);
return array_merge(
parent::options($id),
array_keys($this->generators[$id]->attributes)
array_keys($attributes)
);
} else {
return parent::options($id);
......@@ -146,7 +149,8 @@ class GenerateController extends Controller
public function getActionHelp($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
{
/** @var $action Action */
$attributes = $action->generator->attributes;
unset($attributes['templates']);
$hints = $action->generator->hints();
$options = [];
foreach ($attributes as $name => $value) {
$type = gettype($value);
$options[$name] = [
'type' => 'string',
'type' => $type === 'NULL' ? 'string' : $type,
'required' => $action->generator->isAttributeRequired($name),
'default' => $value,
'comment' => isset($hints[$name]) ? $hints[$name] : '',
'comment' => isset($hints[$name]) ? $this->formatHint($hints[$name]) : '',
];
}
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;
use Yii;
use yii\base\Application;
use yii\base\InlineAction;
use yii\console\Controller;
use yii\console\Exception;
use yii\helpers\Console;
......@@ -302,7 +301,7 @@ class HelpController extends Controller
if (!empty($options)) {
$this->stdout("\nOPTIONS\n\n", Console::BOLD);
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
// show as integer to avoid confusion
$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) !== '') {
$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