Commit af4455eb by Qiang Xue

Finished console support.

Finished migrate command.
parent 6a595de4
...@@ -317,6 +317,11 @@ class Controller extends Component ...@@ -317,6 +317,11 @@ class Controller extends Component
return $this->createView()->renderPartial($view, $params); return $this->createView()->renderPartial($view, $params);
} }
public function renderFile($file, $params = array())
{
return $this->createView()->renderFile($file, $params);
}
public function createView() public function createView()
{ {
return new View($this); return new View($this);
......
...@@ -15,7 +15,7 @@ namespace yii\console; ...@@ -15,7 +15,7 @@ namespace yii\console;
*/ */
class Request extends \yii\base\Request class Request extends \yii\base\Request
{ {
const ANONYMOUS_PARAMS = 'args'; const ANONYMOUS_PARAMS = '-args';
/** /**
* @var string the controller route specified by this request. If this is an empty string, * @var string the controller route specified by this request. If this is an empty string,
......
...@@ -179,17 +179,59 @@ class HelpController extends Controller ...@@ -179,17 +179,59 @@ class HelpController extends Controller
$prefix = $controller->getUniqueId(); $prefix = $controller->getUniqueId();
foreach ($actions as $action) { foreach ($actions as $action) {
if ($action === $controller->defaultAction) { if ($action === $controller->defaultAction) {
echo "* $prefix/$action (default)\n"; echo "* $prefix/$action (default)";
} else { } else {
echo "* $prefix/$action\n"; echo "* $prefix/$action";
} }
$summary = $this->getActionSummary($controller, $action);
if ($summary !== '') {
echo ': ' . $summary;
} }
echo "\n\nTo see the help of each sub-command, enter:\n"; echo "\n";
}
echo "\n\nTo see the detailed information about individual sub-commands, enter:\n";
echo "\n yiic help <sub-command>\n\n"; echo "\n yiic help <sub-command>\n\n";
} }
} }
/** /**
* Returns the short summary of the action.
* @param Controller $controller the controller instance
* @param string $actionID action ID
* @return string the summary about the action
*/
protected function getActionSummary($controller, $actionID)
{
$action = $controller->createAction($actionID);
if ($action === null) {
return '';
}
if ($action instanceof InlineAction) {
$reflection = new \ReflectionMethod($controller, $action->actionMethod);
} else {
$reflection = new \ReflectionClass($action);
}
$tags = $this->parseComment($reflection->getDocComment());
if ($tags['description'] !== '') {
$limit = 73 - strlen($action->getUniqueId());
if ($actionID === $controller->defaultAction) {
$limit -= 10;
}
if ($limit < 0) {
$limit = 50;
}
$description = $tags['description'];
if (($pos = strpos($tags['description'], "\n")) !== false) {
$description = substr($description, 0, $pos);
}
$text = substr($description, 0, $limit);
return strlen($description) > $limit ? $text . '...' : $text;
} else {
return '';
}
}
/**
* Displays the detailed information of a command action. * Displays the detailed information of a command action.
* @param Controller $controller the controller instance * @param Controller $controller the controller instance
* @param string $actionID action ID * @param string $actionID action ID
...@@ -200,7 +242,7 @@ class HelpController extends Controller ...@@ -200,7 +242,7 @@ class HelpController extends Controller
$action = $controller->createAction($actionID); $action = $controller->createAction($actionID);
if ($action === null) { if ($action === null) {
throw new Exception(Yii::t('yii', 'No help for unknown sub-command "{command}".', array( throw new Exception(Yii::t('yii', 'No help for unknown sub-command "{command}".', array(
'{command}' => $action->getUniqueId(), '{command}' => rtrim($controller->getUniqueId() . '/' . $actionID, '/'),
))); )));
} }
if ($action instanceof InlineAction) { if ($action instanceof InlineAction) {
...@@ -232,7 +274,6 @@ class HelpController extends Controller ...@@ -232,7 +274,6 @@ class HelpController extends Controller
echo "\n\n"; echo "\n\n";
if (!empty($required) || !empty($optional)) { if (!empty($required) || !empty($optional)) {
echo "\nARGUMENTS\n\n";
echo implode("\n\n", array_merge($required, $optional)) . "\n\n"; echo implode("\n\n", array_merge($required, $optional)) . "\n\n";
} }
......
<?php
/**
* This view is used by console/controllers/MigrateController.php
* The following variables are available in this view:
*
* @var string $className the new migration class name
*/
echo "<?php\n";
?>
class <?php echo $className; ?> extends \yii\db\Migration
{
public function up()
{
}
public function down()
{
echo "<?php echo $className; ?> cannot be reverted.\n";
return false;
}
}
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