Skip to content

Instantly share code, notes, and snippets.

@dmouse
Created June 8, 2014 21:58
Show Gist options
  • Select an option

  • Save dmouse/3858b461e5e648a6b46f to your computer and use it in GitHub Desktop.

Select an option

Save dmouse/3858b461e5e648a6b46f to your computer and use it in GitHub Desktop.
Your own command in Drupal 8 Console see more in http://symfony.com/doc/current/cookbook/console/console_command.html
<?php
/**
* @file
* Contains \Drupal\Acme\Command\AcmeCommand.
*/
namespace Drupal\Acme\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class AcmeCommand extends Command
{
protected function configure()
{
$this
->setName('demo:greet')
->setDescription('Greet someone')
->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?')
->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
if ($name) {
$text = 'Hello '.$name;
} else {
$text = 'Hello';
}
if ($input->getOption('yell')) {
$text = strtoupper($text);
}
$output->writeln($text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment