Changeset 8418
- Timestamp:
- 04/11/08 16:23:17 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/task/generator/sfGenerateTaskTask.class.php
r8404 r8418 16 16 * @author Francois Zaninotto <francois.zaninotto@symfony-project.com> 17 17 */ 18 class sf TaskInitTask extends sfBaseTask18 class sfGenerateTaskTask extends sfBaseTask 19 19 { 20 20 /** … … 23 23 protected function configure() 24 24 { 25 $this->addArgument('task_name', sfCommandArgument::REQUIRED, 'The task name (can contain namespace)'); 26 $this->addOption('dir', null, sfCommandOption::PARAMETER_OPTIONAL, 'The directory to create the task in', 'lib/task'); 27 $this->addOption('use_database', 'db', sfCommandOption::PARAMETER_OPTIONAL, 'Whether the task needs model initialization to access database', 'true'); 28 $this->addOption('brief_description', 'bd', sfCommandOption::PARAMETER_OPTIONAL, 'A brief task description (appears in task list)', ''); 29 $this->addOption('detailed_description', 'dd', sfCommandOption::PARAMETER_OPTIONAL, 'A usage description (shown in help)', ''); 25 $this->addArguments(array( 26 new sfCommandArgument('task_name', sfCommandArgument::REQUIRED, 'The task name (can contain namespace)'), 27 )); 30 28 31 $this->namespace = 'task'; 32 $this->name = 'init'; 29 $this->addOptions(array( 30 new sfCommandOption('dir', null, sfCommandOption::PARAMETER_OPTIONAL, 'The directory to create the task in', 'lib/task'), 31 new sfCommandOption('use_database', 'db', sfCommandOption::PARAMETER_OPTIONAL, 'Whether the task needs model initialization to access database', 'true'), 32 new sfCommandOption('brief_description', 'bd', sfCommandOption::PARAMETER_OPTIONAL, 'A brief task description (appears in task list)', ''), 33 )); 34 35 $this->namespace = 'generate'; 36 $this->name = 'task'; 33 37 $this->briefDescription = 'Creates a skeleton class for a new task'; 34 38 35 39 $this->detailedDescription = <<<EOF 36 The [ task:init|INFO] creates a new Task class based on the name passed as argument:37 [./symfony task:initnamespace:name|INFO]40 The [generate:task|INFO] creates a new Task class based on the name passed as argument: 41 [./symfony generate:task namespace:name|INFO] 38 42 39 43 The `fooBarTask.class.php` skeleton task is created under the `lib/task/` directory. Note that the namespace is optional. 40 44 If you want to create the file in another directory (relative to the project root folder), pass it in the [dir|INFO] option: 41 [./symfony task:initnamespace:name --dir=plugins/myPlugin/lib/task|INFO]45 [./symfony generate:task namespace:name --dir=plugins/myPlugin/lib/task|INFO] 42 46 43 47 If the task doesn't need database access, you can remove the database initialization code with the [use_database|INFO] option: 44 [./symfony task:initnamespace:name --use_database=false|INFO]48 [./symfony generate:task namespace:name --use_database=false|INFO] 45 49 46 50 You can also specify a description: 47 [./symfony task:initnamespace:name --briefDescription='Does interesting things' --detailedDescription='Usage tutorial'|INFO]51 [./symfony generate:task namespace:name --briefDescription='Does interesting things' --detailedDescription='Usage tutorial'|INFO] 48 52 EOF; 49 53 } … … 60 64 $taskClassName = ($namespace ? $namespace.ucfirst($name) : $name) . 'Task'; 61 65 $briefDescription = $options['brief_description']; 62 $detailedDescription = $options['detailed_description'] ? $options['detailed_description'] :<<<HED66 $detailedDescription = <<<HED 63 67 The [$taskName|INFO] task does things. 64 68 Call it with: … … 125 129 { 126 130 // add code here 127 128 131 } 129 132 } … … 136 139 $this->getFilesystem()->mkdirs(str_replace('/', DIRECTORY_SEPARATOR, $options['dir'])); 137 140 } 141 138 142 $taskFile = sfConfig::get('sf_root_dir').'/'.$options['dir'].'/'.$taskClassName.'.class.php'; 139 143 if (is_readable($taskFile)) 140 144 { 141 throw new sfCommandException(sprintf('A "%s" task already exists in %s', $taskName, $taskFile));145 throw new sfCommandException(sprintf('A "%s" task already exists in "%s".', $taskName, $taskFile)); 142 146 } 143 144 $this->logSection(' init', sprintf('Creating "%s" task file', $taskFile));147 148 $this->logSection('task', sprintf('Creating "%s" task file', $taskFile)); 145 149 file_put_contents($taskFile, $content); 146 150 } 147 148 151 }

