diff --git a/extensions/gii/console/GenerateController.php b/extensions/gii/console/GenerateController.php index 6dbd937cc0..ba197529e2 100644 --- a/extensions/gii/console/GenerateController.php +++ b/extensions/gii/console/GenerateController.php @@ -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('%(.*?)%', '\1', $hint); + $hint = preg_replace('/\s+/', ' ', $hint); + return wordwrap($hint); + } } diff --git a/framework/console/controllers/HelpController.php b/framework/console/controllers/HelpController.php index 3ee0e4c004..8e13f7e62f 100644 --- a/framework/console/controllers/HelpController.php +++ b/framework/console/controllers/HelpController.php @@ -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; }