You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					75 lines
				
				2.0 KiB
			
		
		
			
		
	
	
					75 lines
				
				2.0 KiB
			| 
								 
											14 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 * HelpCommand class file.
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @author Qiang Xue <qiang.xue@gmail.com>
							 | 
						||
| 
								 | 
							
								 * @link http://www.yiiframework.com/
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 * @copyright Copyright © 2008-2012 Yii Software LLC
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 * @license http://www.yiiframework.com/license/
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace yii\console;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 * HelpCommand represents a console help command.
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 *
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 * HelpCommand displays the available command list or the help instructions
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								 * about a specific command.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * To use this command, enter the following on the command line:
							 | 
						||
| 
								 | 
							
								 * <pre>
							 | 
						||
| 
								 | 
							
								 * php path/to/entry_script.php help [command name]
							 | 
						||
| 
								 | 
							
								 * </pre>
							 | 
						||
| 
								 | 
							
								 * In the above, if the command name is not provided, it will display all
							 | 
						||
| 
								 | 
							
								 * available commands.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @property string $help The command description.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @author Qiang Xue <qiang.xue@gmail.com>
							 | 
						||
| 
								 | 
							
								 * @since 2.0
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								class HelpCommand extends Command
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * Execute the action.
							 | 
						||
| 
								 | 
							
									 * @param array $args command line parameters specific for this command
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									public function run($args)
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										$runner=$this->getCommandRunner();
							 | 
						||
| 
								 | 
							
										$commands=$runner->commands;
							 | 
						||
| 
								 | 
							
										if(isset($args[0]))
							 | 
						||
| 
								 | 
							
										{
							 | 
						||
| 
								 | 
							
											$name=strtolower($args[0]);
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										if(!isset($args[0]) || !isset($commands[$name]))
							 | 
						||
| 
								 | 
							
										{
							 | 
						||
| 
								 | 
							
											if(!empty($commands))
							 | 
						||
| 
								 | 
							
											{
							 | 
						||
| 
								 | 
							
												echo "Yii command runner (based on Yii v".\Yii::getVersion().")\n";
							 | 
						||
| 
								 | 
							
												echo "Usage: ".$runner->getScriptName()." <command-name> [parameters...]\n";
							 | 
						||
| 
								 | 
							
												echo "\nThe following commands are available:\n";
							 | 
						||
| 
								 | 
							
												$commandNames=array_keys($commands);
							 | 
						||
| 
								 | 
							
												sort($commandNames);
							 | 
						||
| 
								 | 
							
												echo ' - '.implode("\n - ",$commandNames);
							 | 
						||
| 
								 | 
							
												echo "\n\nTo see individual command help, use the following:\n";
							 | 
						||
| 
								 | 
							
												echo "   ".$runner->getScriptName()." help <command-name>\n";
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
											} else
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
											{
							 | 
						||
| 
								 | 
							
												echo "No available commands.\n";
							 | 
						||
| 
								 | 
							
												echo "Please define them under the following directory:\n";
							 | 
						||
| 
								 | 
							
												echo "\t".\Yii::$app->getCommandPath()."\n";
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
										} else
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
											echo $runner->createCommand($name)->getHelp();
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * Provides the command description.
							 | 
						||
| 
								 | 
							
									 * @return string the command description.
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 | 
							
									public function getHelp()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return parent::getHelp().' [command-name]';
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 |