@@ -12,8 +12,10 @@ if ($opts['json']) {
12
12
return ;
13
13
}
14
14
15
- print tableize ('Production Changes ' , $ prod );
16
- print tableize ('Dev Changes ' , $ dev );
15
+ $ table_opts = ($ opts ['md ' ]) ? array ('capped ' => false , 'joint ' => '| ' ) : array ();
16
+
17
+ print tableize ('Production Changes ' , $ prod , $ table_opts );
18
+ print tableize ('Dev Changes ' , $ dev , $ table_opts );
17
19
18
20
function diff ($ key , $ from , $ to , $ base_path ) {
19
21
@@ -57,9 +59,11 @@ function version($pkg)
57
59
return $ version ;
58
60
}
59
61
60
- function tableize ($ header , $ data ) {
62
+ function tableize ($ header , $ data, $ opts = array () ) {
61
63
if (empty ($ data )) return '' ;
62
64
65
+ $ opts = array_merge (array ('capped ' => true , 'joint ' => '+ ' ), $ opts );
66
+
63
67
$ widths = array (maxLength (array_merge (array ($ header ), array_keys ($ data ))));
64
68
65
69
for ($ i = 0 ; $ i < count (reset ($ data )); $ i ++) {
@@ -68,17 +72,26 @@ function tableize($header, $data) {
68
72
69
73
$ total_width = array_sum ($ widths ) + (count ($ widths ) * 3 ) + 1 ;
70
74
71
- $ lines [] = '+ ' . str_repeat ('- ' , $ total_width - 2 ) . '+ ' ;
75
+ if ($ opts ['capped ' ]) {
76
+ $ lines [] = separatorLine ($ widths , $ opts ['joint ' ]);
77
+ }
78
+
72
79
$ lines [] = tabelizeLine (array ($ header , 'From ' , 'To ' ), $ widths );
73
- $ lines [] = ' + ' . str_repeat ( ' - ' , $ total_width - 2 ) . ' + ' ;
80
+ $ lines [] = separatorLine ( $ widths , $ opts [ ' joint ' ]) ;
74
81
75
82
foreach ($ data as $ key => $ v ) {
76
83
$ lines [] = tabelizeLine (array_merge (array ($ key ), $ v ), $ widths );
77
84
}
78
85
79
- $ lines [] = '+ ' . str_repeat ('- ' , $ total_width - 2 ) . '+ ' ;
86
+ if ($ opts ['capped ' ]) {
87
+ $ lines [] = separatorLine ($ widths , $ opts ['joint ' ]);
88
+ }
89
+
90
+ return implode (PHP_EOL , array_filter ($ lines )) . PHP_EOL . PHP_EOL ;
91
+ }
80
92
81
- return implode (PHP_EOL , $ lines ) . PHP_EOL ;
93
+ function separatorLine ($ widths , $ joint ) {
94
+ return $ joint . implode ($ joint , array_map (function ($ n ) { return str_repeat ('- ' , $ n + 2 ); }, $ widths )) . $ joint ;
82
95
}
83
96
84
97
function maxLength (array $ array ) {
@@ -141,7 +154,7 @@ function mustDecodeJson($json, $context) {
141
154
}
142
155
143
156
function parseOpts () {
144
- $ given = getopt ('hp: ' , array ('path: ' , 'from: ' , 'to: ' , 'json ' , 'pretty ' , 'help ' ));
157
+ $ given = getopt ('hp: ' , array ('path: ' , 'from: ' , 'to: ' , 'md ' , ' json ' , 'pretty ' , 'help ' ));
145
158
146
159
foreach (array ('help ' => 'h ' , 'path ' => 'p ' ) as $ long => $ short ) {
147
160
if (array_key_exists ($ short , $ given )) {
@@ -158,6 +171,7 @@ function parseOpts() {
158
171
'path ' => array_key_exists ('path ' , $ given ) ? $ given ['path ' ] : '' ,
159
172
'from ' => array_key_exists ('from ' , $ given ) ? $ given ['from ' ] : 'HEAD ' ,
160
173
'to ' => array_key_exists ('to ' , $ given ) ? $ given ['to ' ] : '' ,
174
+ 'md ' => array_key_exists ('md ' , $ given ),
161
175
'json ' => array_key_exists ('json ' , $ given ),
162
176
'pretty ' => version_compare (PHP_VERSION , '5.4.0 ' , '>= ' ) && array_key_exists ('pretty ' , $ given ),
163
177
);
@@ -175,6 +189,7 @@ Options:
175
189
--to The file, git ref, or git ref with filename to compare to (composer.lock)
176
190
--json Format output as JSON
177
191
--pretty Pretty print JSON output (PHP >= 5.4.0)
192
+ --md Use markdown instead of plain text
178
193
179
194
EOF ;
180
195
0 commit comments