From dbe3234b56a85de408e5a961df5a3ac832530a2e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 4 Aug 2012 13:57:14 -0400 Subject: [PATCH] Refactor help to show up on console -h as well. --- lib/Cake/Console/Command/ConsoleShell.php | 129 +++++++++++++--------- 1 file changed, 74 insertions(+), 55 deletions(-) diff --git a/lib/Cake/Console/Command/ConsoleShell.php b/lib/Cake/Console/Command/ConsoleShell.php index 9d8c54e3b..e9d528ca9 100644 --- a/lib/Cake/Console/Command/ConsoleShell.php +++ b/lib/Cake/Console/Command/ConsoleShell.php @@ -74,67 +74,86 @@ class ConsoleShell extends AppShell { } } + public function getOptionParser() { + $description = array( + 'The interactive console is a tool for testing parts of your', + 'app before you write code.', + '', + 'See below for a list of supported commands.' + ); + + $epilog = array( + 'Model testing', + '', + 'To test model results, use the name of your model without a leading $', + 'e.g. Foo->find("all")', + "", + 'To dynamically set associations, you can do the following:', + '', + "\tModelA bind ModelB", + '', + "where the supported associations are hasOne, hasMany, belongsTo, hasAndBelongsToMany", + "", + 'To dynamically remove associations, you can do the following:', + '', + "\t ModelA unbind ModelB", + '', + "where the supported associations are the same as above", + "", + "To save a new field in a model, you can do the following:", + '', + "\tModelA->save(array('foo' => 'bar', 'baz' => 0))", + '', + "where you are passing a hash of data to be saved in the format", + "of field => value pairs", + "", + "To get column information for a model, use the following:", + '', + "\tModelA columns", + '', + "which returns a list of columns and their type", + "", + 'Route testing', + "", + 'To test URLs against your app\'s route configuration, type:', + "", + "\tRoute ", + "", + "where url is the path to your your action plus any query parameters,", + "minus the application's base path. For example:", + "", + "\tRoute /posts/view/1", + "", + "will return something like the following:", + "", + "\tarray(", + "\t [...]", + "\t 'controller' => 'posts',", + "\t 'action' => 'view',", + "\t [...]", + "\t)", + "", + 'Alternatively, you can use simple array syntax to test reverse', + 'To reload your routes config (Config/routes.php), do the following:', + "", + "\tRoutes reload", + "", + 'To show all connected routes, do the following:', + '', + "\tRoutes show", + ); + return parent::getOptionParser() + ->description($description) + ->epilog($epilog); + } /** * Prints the help message * * @return void */ public function help() { - $out = 'Console help:'; - $out .= '-------------'; - $out .= 'The interactive console is a tool for testing parts of your app before you'; - $out .= 'write code.'; - $out .= "\n"; - $out .= 'Model testing:'; - $out .= 'To test model results, use the name of your model without a leading $'; - $out .= 'e.g. Foo->find("all")'; - $out .= "\n"; - $out .= 'To dynamically set associations, you can do the following:'; - $out .= "\tModelA bind ModelB"; - $out .= "where the supported associations are hasOne, hasMany, belongsTo, hasAndBelongsToMany"; - $out .= "\n"; - $out .= 'To dynamically remove associations, you can do the following:'; - $out .= "\t ModelA unbind ModelB"; - $out .= "where the supported associations are the same as above"; - $out .= "\n"; - $out .= "To save a new field in a model, you can do the following:"; - $out .= "\tModelA->save(array('foo' => 'bar', 'baz' => 0))"; - $out .= "where you are passing a hash of data to be saved in the format"; - $out .= "of field => value pairs"; - $out .= "\n"; - $out .= "To get column information for a model, use the following:"; - $out .= "\tModelA columns"; - $out .= "which returns a list of columns and their type"; - $out .= "\n"; - $out .= "\n"; - $out .= 'Route testing:'; - $out .= "\n"; - $out .= 'To test URLs against your app\'s route configuration, type:'; - $out .= "\n"; - $out .= "\tRoute "; - $out .= "\n"; - $out .= "where url is the path to your your action plus any query parameters,"; - $out .= "minus the application's base path. For example:"; - $out .= "\n"; - $out .= "\tRoute /posts/view/1"; - $out .= "\n"; - $out .= "will return something like the following:"; - $out .= "\n"; - $out .= "\tarray("; - $out .= "\t [...]"; - $out .= "\t 'controller' => 'posts',"; - $out .= "\t 'action' => 'view',"; - $out .= "\t [...]"; - $out .= "\t)"; - $out .= "\n"; - $out .= 'Alternatively, you can use simple array syntax to test reverse'; - $out .= 'To reload your routes config (Config/routes.php), do the following:'; - $out .= "\n"; - $out .= "\tRoutes reload"; - $out .= "\n"; - $out .= 'To show all connected routes, do the following:'; - $out .= "\tRoutes show"; - $this->out($out); + $optionParser = $this->getOptionParser(); + $this->out($optionParser->epilog()); } /**