@@ -12,8 +12,10 @@ if ($opts['json']) {
1212 return ;
1313}
1414
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 );
1719
1820function diff ($ key , $ from , $ to , $ base_path ) {
1921
@@ -57,9 +59,11 @@ function version($pkg)
5759 return $ version ;
5860}
5961
60- function tableize ($ header , $ data ) {
62+ function tableize ($ header , $ data, $ opts = array () ) {
6163 if (empty ($ data )) return '' ;
6264
65+ $ opts = array_merge (array ('capped ' => true , 'joint ' => '+ ' ), $ opts );
66+
6367 $ widths = array (maxLength (array_merge (array ($ header ), array_keys ($ data ))));
6468
6569 for ($ i = 0 ; $ i < count (reset ($ data )); $ i ++) {
@@ -68,17 +72,26 @@ function tableize($header, $data) {
6872
6973 $ total_width = array_sum ($ widths ) + (count ($ widths ) * 3 ) + 1 ;
7074
71- $ lines [] = '+ ' . str_repeat ('- ' , $ total_width - 2 ) . '+ ' ;
75+ if ($ opts ['capped ' ]) {
76+ $ lines [] = separatorLine ($ widths , $ opts ['joint ' ]);
77+ }
78+
7279 $ lines [] = tabelizeLine (array ($ header , 'From ' , 'To ' ), $ widths );
73- $ lines [] = ' + ' . str_repeat ( ' - ' , $ total_width - 2 ) . ' + ' ;
80+ $ lines [] = separatorLine ( $ widths , $ opts [ ' joint ' ]) ;
7481
7582 foreach ($ data as $ key => $ v ) {
7683 $ lines [] = tabelizeLine (array_merge (array ($ key ), $ v ), $ widths );
7784 }
7885
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+ }
8092
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 ;
8295}
8396
8497function maxLength (array $ array ) {
@@ -141,7 +154,7 @@ function mustDecodeJson($json, $context) {
141154}
142155
143156function parseOpts () {
144- $ given = getopt ('hp: ' , array ('path: ' , 'from: ' , 'to: ' , 'json ' , 'pretty ' , 'help ' ));
157+ $ given = getopt ('hp: ' , array ('path: ' , 'from: ' , 'to: ' , 'md ' , ' json ' , 'pretty ' , 'help ' ));
145158
146159 foreach (array ('help ' => 'h ' , 'path ' => 'p ' ) as $ long => $ short ) {
147160 if (array_key_exists ($ short , $ given )) {
@@ -158,6 +171,7 @@ function parseOpts() {
158171 'path ' => array_key_exists ('path ' , $ given ) ? $ given ['path ' ] : '' ,
159172 'from ' => array_key_exists ('from ' , $ given ) ? $ given ['from ' ] : 'HEAD ' ,
160173 'to ' => array_key_exists ('to ' , $ given ) ? $ given ['to ' ] : '' ,
174+ 'md ' => array_key_exists ('md ' , $ given ),
161175 'json ' => array_key_exists ('json ' , $ given ),
162176 'pretty ' => version_compare (PHP_VERSION , '5.4.0 ' , '>= ' ) && array_key_exists ('pretty ' , $ given ),
163177 );
@@ -175,6 +189,7 @@ Options:
175189 --to The file, git ref, or git ref with filename to compare to (composer.lock)
176190 --json Format output as JSON
177191 --pretty Pretty print JSON output (PHP >= 5.4.0)
192+ --md Use markdown instead of plain text
178193
179194EOF ;
180195
0 commit comments