forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.php.twig
More file actions
64 lines (55 loc) · 1.59 KB
/
Copy pathcommand.php.twig
File metadata and controls
64 lines (55 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{% extends "base/class.php.twig" %}
{% block file_path %}
Drupal\{{module_name}}\Command\{{ name.class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module_name}}\Command;
{% endblock %}
{% block use_class %}
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\AppConsole\Command\ContainerAwareCommand;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ name.class }}.
*
* @package Drupal\{{module_name}}
*/
class {{ name.class }} extends ContainerAwareCommand {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function configure() {
$this
->setName('{{ command }}')
->setDescription($this->trans('{{ command_key_root }}.description'))
->addArgument('name', InputArgument::OPTIONAL, $this->trans('{{ command_key_root }}.arguments.name'))
->addOption('yell', NULL, InputOption::VALUE_NONE, $this->trans('{{ command_key_root }}.options.yell'));
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$name = $input->getArgument('name');
if ($name) {
$text = 'Hello ' . $name;
}
else {
$text = 'Hello';
}
$text = sprintf(
'%s, %s: %s',
$text,
'I am a new generated command for the module',
$this->getModule()
);
if ($input->getOption('yell')) {
$text = strtoupper($text);
}
$output->writeln($text);
}
{% endblock %}