Skip to content

Commit 95ba10d

Browse files
committed
feature symfony#20866 [Console] Improve markdown format (ro0NL)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Console] Improve markdown format | Q | A | ------------- | --- | Branch? | "master" | Bug fix? | no | New feature? | no | BC breaks? | not sure? | Deprecations? | no | Tests pass? | yes | Fixed tickets | comma-separated list of tickets fixed by the PR, if any | License | MIT | Doc PR | reference to the documentation PR, if any This improves the markdown description for a console application. To make the ouput read more friendly and intuitively (less bloated IMHO). Before: Markdown files in https://github.com/symfony/symfony/tree/master/src/Symfony/Component/Console/Tests/Fixtures After: Markdown files in https://github.com/ro0NL/symfony/tree/console/markdown/src/Symfony/Component/Console/Tests/Fixtures Commits ------- 302a19d [Console] Improve markdown format
2 parents 7e657b8 + 302a19d commit 95ba10d

18 files changed

+259
-315
lines changed

src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ class MarkdownDescriptor extends Descriptor
3232
protected function describeInputArgument(InputArgument $argument, array $options = array())
3333
{
3434
$this->write(
35-
'**'.$argument->getName().':**'."\n\n"
36-
.'* Name: '.($argument->getName() ?: '<none>')."\n"
35+
'#### `'.($argument->getName() ?: '<none>')."`\n\n"
36+
.($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\n" : '')
3737
.'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
3838
.'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
39-
.'* Description: '.preg_replace('/\s*[\r\n]\s*/', "\n ", $argument->getDescription() ?: '<none>')."\n"
4039
.'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
4140
);
4241
}
@@ -46,14 +45,17 @@ protected function describeInputArgument(InputArgument $argument, array $options
4645
*/
4746
protected function describeInputOption(InputOption $option, array $options = array())
4847
{
48+
$name = '--'.$option->getName();
49+
if ($option->getShortcut()) {
50+
$name .= '|-'.implode('|-', explode('|', $option->getShortcut())).'';
51+
}
52+
4953
$this->write(
50-
'**'.$option->getName().':**'."\n\n"
51-
.'* Name: `--'.$option->getName().'`'."\n"
52-
.'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n"
54+
'#### `'.$name.'`'."\n\n"
55+
.($option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $option->getDescription())."\n\n" : '')
5356
.'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
5457
.'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
5558
.'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
56-
.'* Description: '.preg_replace('/\s*[\r\n]\s*/', "\n ", $option->getDescription() ?: '<none>')."\n"
5759
.'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
5860
);
5961
}
@@ -64,7 +66,7 @@ protected function describeInputOption(InputOption $option, array $options = arr
6466
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
6567
{
6668
if ($showArguments = count($definition->getArguments()) > 0) {
67-
$this->write('### Arguments:');
69+
$this->write('### Arguments');
6870
foreach ($definition->getArguments() as $argument) {
6971
$this->write("\n\n");
7072
$this->write($this->describeInputArgument($argument));
@@ -76,7 +78,7 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
7678
$this->write("\n\n");
7779
}
7880

79-
$this->write('### Options:');
81+
$this->write('### Options');
8082
foreach ($definition->getOptions() as $option) {
8183
$this->write("\n\n");
8284
$this->write($this->describeInputOption($option));
@@ -93,12 +95,12 @@ protected function describeCommand(Command $command, array $options = array())
9395
$command->mergeApplicationDefinition(false);
9496

9597
$this->write(
96-
$command->getName()."\n"
97-
.str_repeat('-', strlen($command->getName()))."\n\n"
98-
.'* Description: '.($command->getDescription() ?: '<none>')."\n"
99-
.'* Usage:'."\n\n"
98+
'`'.$command->getName()."`\n"
99+
.str_repeat('-', strlen($command->getName()) + 2)."\n\n"
100+
.($command->getDescription() ? $command->getDescription()."\n\n" : '')
101+
.'### Usage'."\n\n"
100102
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
101-
return $carry.' * `'.$usage.'`'."\n";
103+
return $carry.'* `'.$usage.'`'."\n";
102104
})
103105
);
104106

@@ -121,7 +123,7 @@ protected function describeApplication(Application $application, array $options
121123
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
122124
$description = new ApplicationDescription($application, $describedNamespace);
123125

124-
$this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));
126+
$this->write($application->getLongVersion()."\n".str_repeat('=', strlen($application->getLongVersion())));
125127

126128
foreach ($description->getNamespaces() as $namespace) {
127129
if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
@@ -131,7 +133,7 @@ protected function describeApplication(Application $application, array $options
131133

132134
$this->write("\n\n");
133135
$this->write(implode("\n", array_map(function ($commandName) {
134-
return '* '.$commandName;
136+
return '* `'.$commandName.'`';
135137
}, $namespace['commands'])));
136138
}
137139

Lines changed: 59 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
UNKNOWN
2-
=======
1+
Console Tool
2+
============
33

4-
* help
5-
* list
4+
* `help`
5+
* `list`
66

7-
help
8-
----
7+
`help`
8+
------
99

10-
* Description: Displays help for a command
11-
* Usage:
10+
Displays help for a command
1211

13-
* `help [--format FORMAT] [--raw] [--] [<command_name>]`
12+
### Usage
13+
14+
* `help [--format FORMAT] [--raw] [--] [<command_name>]`
1415

1516
The <info>help</info> command displays help for a given command:
1617

@@ -22,115 +23,107 @@ You can also output the help in other formats by using the <comment>--format</co
2223

2324
To display the list of available commands, please use the <info>list</info> command.
2425

25-
### Arguments:
26+
### Arguments
27+
28+
#### `command_name`
2629

27-
**command_name:**
30+
The command name
2831

29-
* Name: command_name
3032
* Is required: no
3133
* Is array: no
32-
* Description: The command name
3334
* Default: `'help'`
3435

35-
### Options:
36+
### Options
3637

37-
**format:**
38+
#### `--format`
39+
40+
The output format (txt, xml, json, or md)
3841

39-
* Name: `--format`
40-
* Shortcut: <none>
4142
* Accept value: yes
4243
* Is value required: yes
4344
* Is multiple: no
44-
* Description: The output format (txt, xml, json, or md)
4545
* Default: `'txt'`
4646

47-
**raw:**
47+
#### `--raw`
48+
49+
To output raw command help
4850

49-
* Name: `--raw`
50-
* Shortcut: <none>
5151
* Accept value: no
5252
* Is value required: no
5353
* Is multiple: no
54-
* Description: To output raw command help
5554
* Default: `false`
5655

57-
**help:**
56+
#### `--help|-h`
57+
58+
Display this help message
5859

59-
* Name: `--help`
60-
* Shortcut: `-h`
6160
* Accept value: no
6261
* Is value required: no
6362
* Is multiple: no
64-
* Description: Display this help message
6563
* Default: `false`
6664

67-
**quiet:**
65+
#### `--quiet|-q`
66+
67+
Do not output any message
6868

69-
* Name: `--quiet`
70-
* Shortcut: `-q`
7169
* Accept value: no
7270
* Is value required: no
7371
* Is multiple: no
74-
* Description: Do not output any message
7572
* Default: `false`
7673

77-
**verbose:**
74+
#### `--verbose|-v|-vv|-vvv`
75+
76+
Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
7877

79-
* Name: `--verbose`
80-
* Shortcut: `-v|-vv|-vvv`
8178
* Accept value: no
8279
* Is value required: no
8380
* Is multiple: no
84-
* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
8581
* Default: `false`
8682

87-
**version:**
83+
#### `--version|-V`
84+
85+
Display this application version
8886

89-
* Name: `--version`
90-
* Shortcut: `-V`
9187
* Accept value: no
9288
* Is value required: no
9389
* Is multiple: no
94-
* Description: Display this application version
9590
* Default: `false`
9691

97-
**ansi:**
92+
#### `--ansi`
93+
94+
Force ANSI output
9895

99-
* Name: `--ansi`
100-
* Shortcut: <none>
10196
* Accept value: no
10297
* Is value required: no
10398
* Is multiple: no
104-
* Description: Force ANSI output
10599
* Default: `false`
106100

107-
**no-ansi:**
101+
#### `--no-ansi`
102+
103+
Disable ANSI output
108104

109-
* Name: `--no-ansi`
110-
* Shortcut: <none>
111105
* Accept value: no
112106
* Is value required: no
113107
* Is multiple: no
114-
* Description: Disable ANSI output
115108
* Default: `false`
116109

117-
**no-interaction:**
110+
#### `--no-interaction|-n`
111+
112+
Do not ask any interactive question
118113

119-
* Name: `--no-interaction`
120-
* Shortcut: `-n`
121114
* Accept value: no
122115
* Is value required: no
123116
* Is multiple: no
124-
* Description: Do not ask any interactive question
125117
* Default: `false`
126118

127-
list
128-
----
119+
`list`
120+
------
121+
122+
Lists commands
129123

130-
* Description: Lists commands
131-
* Usage:
124+
### Usage
132125

133-
* `list [--raw] [--format FORMAT] [--] [<namespace>]`
126+
* `list [--raw] [--format FORMAT] [--] [<namespace>]`
134127

135128
The <info>list</info> command lists all commands:
136129

@@ -148,34 +141,32 @@ It's also possible to get raw list of commands (useful for embedding command run
148141

149142
<info>php app/console list --raw</info>
150143

151-
### Arguments:
144+
### Arguments
152145

153-
**namespace:**
146+
#### `namespace`
147+
148+
The namespace name
154149

155-
* Name: namespace
156150
* Is required: no
157151
* Is array: no
158-
* Description: The namespace name
159152
* Default: `NULL`
160153

161-
### Options:
154+
### Options
155+
156+
#### `--raw`
162157

163-
**raw:**
158+
To output raw command list
164159

165-
* Name: `--raw`
166-
* Shortcut: <none>
167160
* Accept value: no
168161
* Is value required: no
169162
* Is multiple: no
170-
* Description: To output raw command list
171163
* Default: `false`
172164

173-
**format:**
165+
#### `--format`
166+
167+
The output format (txt, xml, json, or md)
174168

175-
* Name: `--format`
176-
* Shortcut: <none>
177169
* Accept value: yes
178170
* Is value required: yes
179171
* Is multiple: no
180-
* Description: The output format (txt, xml, json, or md)
181172
* Default: `'txt'`

0 commit comments

Comments
 (0)