- Create a new task class in
src/Butler/Task/
extendingAbstractTask
. - Now you can create public functions with a $config param which is an array. (function name = task name)
- If a task function return an array, the values are merged in to the project config. Multidimensional Arrays are supported and can be used in following task configs like this: {level1.sub2.myvar}
- Use $this->execute(); to execute a cli command; Example:
$this->execute('composer-install');
- (tbd) Use $this->writeln(); to write some text on the commandline. Example
$this->writeln('project installed');
- (tbd) Use $this->question(); to send a question input. Example:
$answer = $this->question('Description for Github project', 'This is a default description');
- Use project configuration:
$config['project']['mykey']
(tbd)->(usage like $this->getProjectConfig('mykey') ) - Use task configuration:
$config['options']['task-option-key']
(tbd)->(usage like $this->getOption('description') )
Example:
<?php
namespace Butler\Task;
class MyTask extends AbstractTask
{
/**
* @param array $options
*/
public function create(array $config) {
$this->execute('composer create-project '. (!isset($config['options']['params'])? '' : implode(' ', $config['options']['params'])) .' '. $config['options']['distribution'].' '.$config['options']['tempPath'] );
$this->execute('shopt -s dotglob && mv '. $config['options']['tempPath'] .'/* ./');
$this->execute('rm -Rf '. $config['options']['tempPath']);
}
/**
* @param array $config
*/
public function add(array $config) {
if (isset($config['options']['package'])) {
$this->writeln('These packages will installed: ' .$config['options']['package']);
}
$additionalpackages = $this->question('Add additional packages: ', '');
$this->execute('composer require '. (!isset($config['options']['params'])? '' : implode(' ', $config['options']['params'])) . $additionalpackages . ' '. $config['options']['package'] );
}
/**
* @param array $options
*/
public function remove(array $options) {
$this->execute('composer remove '.$options['package']);
}
}