Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/console/Descriptor/MarkdownDescriptor.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Console\Descriptor; | |
13 | |
14 use Symfony\Component\Console\Application; | |
15 use Symfony\Component\Console\Command\Command; | |
16 use Symfony\Component\Console\Helper\Helper; | |
17 use Symfony\Component\Console\Input\InputArgument; | |
18 use Symfony\Component\Console\Input\InputDefinition; | |
19 use Symfony\Component\Console\Input\InputOption; | |
20 | |
21 /** | |
22 * Markdown descriptor. | |
23 * | |
24 * @author Jean-François Simon <contact@jfsimon.fr> | |
25 * | |
26 * @internal | |
27 */ | |
28 class MarkdownDescriptor extends Descriptor | |
29 { | |
30 /** | |
31 * {@inheritdoc} | |
32 */ | |
33 protected function describeInputArgument(InputArgument $argument, array $options = array()) | |
34 { | |
35 $this->write( | |
36 '**'.$argument->getName().':**'."\n\n" | |
37 .'* Name: '.($argument->getName() ?: '<none>')."\n" | |
38 .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n" | |
39 .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n" | |
40 .'* Description: '.preg_replace('/\s*[\r\n]\s*/', "\n ", $argument->getDescription() ?: '<none>')."\n" | |
41 .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`' | |
42 ); | |
43 } | |
44 | |
45 /** | |
46 * {@inheritdoc} | |
47 */ | |
48 protected function describeInputOption(InputOption $option, array $options = array()) | |
49 { | |
50 $this->write( | |
51 '**'.$option->getName().':**'."\n\n" | |
52 .'* Name: `--'.$option->getName().'`'."\n" | |
53 .'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n" | |
54 .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n" | |
55 .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n" | |
56 .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n" | |
57 .'* Description: '.preg_replace('/\s*[\r\n]\s*/', "\n ", $option->getDescription() ?: '<none>')."\n" | |
58 .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`' | |
59 ); | |
60 } | |
61 | |
62 /** | |
63 * {@inheritdoc} | |
64 */ | |
65 protected function describeInputDefinition(InputDefinition $definition, array $options = array()) | |
66 { | |
67 if ($showArguments = count($definition->getArguments()) > 0) { | |
68 $this->write('### Arguments:'); | |
69 foreach ($definition->getArguments() as $argument) { | |
70 $this->write("\n\n"); | |
71 $this->write($this->describeInputArgument($argument)); | |
72 } | |
73 } | |
74 | |
75 if (count($definition->getOptions()) > 0) { | |
76 if ($showArguments) { | |
77 $this->write("\n\n"); | |
78 } | |
79 | |
80 $this->write('### Options:'); | |
81 foreach ($definition->getOptions() as $option) { | |
82 $this->write("\n\n"); | |
83 $this->write($this->describeInputOption($option)); | |
84 } | |
85 } | |
86 } | |
87 | |
88 /** | |
89 * {@inheritdoc} | |
90 */ | |
91 protected function describeCommand(Command $command, array $options = array()) | |
92 { | |
93 $command->getSynopsis(); | |
94 $command->mergeApplicationDefinition(false); | |
95 | |
96 $this->write( | |
97 $command->getName()."\n" | |
98 .str_repeat('-', Helper::strlen($command->getName()))."\n\n" | |
99 .'* Description: '.($command->getDescription() ?: '<none>')."\n" | |
100 .'* Usage:'."\n\n" | |
101 .array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) { | |
102 return $carry.' * `'.$usage.'`'."\n"; | |
103 }) | |
104 ); | |
105 | |
106 if ($help = $command->getProcessedHelp()) { | |
107 $this->write("\n"); | |
108 $this->write($help); | |
109 } | |
110 | |
111 if ($command->getNativeDefinition()) { | |
112 $this->write("\n\n"); | |
113 $this->describeInputDefinition($command->getNativeDefinition()); | |
114 } | |
115 } | |
116 | |
117 /** | |
118 * {@inheritdoc} | |
119 */ | |
120 protected function describeApplication(Application $application, array $options = array()) | |
121 { | |
122 $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; | |
123 $description = new ApplicationDescription($application, $describedNamespace); | |
124 | |
125 $this->write($application->getName()."\n".str_repeat('=', Helper::strlen($application->getName()))); | |
126 | |
127 foreach ($description->getNamespaces() as $namespace) { | |
128 if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { | |
129 $this->write("\n\n"); | |
130 $this->write('**'.$namespace['id'].':**'); | |
131 } | |
132 | |
133 $this->write("\n\n"); | |
134 $this->write(implode("\n", array_map(function ($commandName) { | |
135 return '* '.$commandName; | |
136 }, $namespace['commands']))); | |
137 } | |
138 | |
139 foreach ($description->getCommands() as $command) { | |
140 $this->write("\n\n"); | |
141 $this->write($this->describeCommand($command)); | |
142 } | |
143 } | |
144 } |