Skip to content

Commit 429f882

Browse files
committed
Adds --md, markdown output
1 parent 4d093d5 commit 429f882

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

README.md

+55-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Or from vim, to insert the output into the commit message, type `:r!composer-loc
3333
- `--path, -p`: Base to with which to prefix paths. Default "./"
3434
- `--from`: The file^, git ref, or git ref with filename to compare from (HEAD:composer.lock)
3535
- `--to`: The file^, git ref, or git ref with filename to compare to (composer.lock)
36+
- `--md`: Markdown table output
3637
- `--json`: json output
3738
- `--pretty`: pretty output when combined with `--json` (>=5.4 only)
3839

@@ -42,25 +43,73 @@ Example Table Output
4243
====================
4344

4445
```
45-
+---------------------------------------------------------+
46+
+----------------------------------+------------+---------+
4647
| Production Changes | From | To |
47-
+---------------------------------------------------------+
48+
+----------------------------------+------------+---------+
4849
| guzzlehttp/guzzle | 6.2.0 | 6.2.1 |
4950
| hashids/hashids | 1.0.5 | 1.0.6 |
5051
| laravel/framework | v5.1.27 | v5.1.44 |
5152
| league/flysystem | 1.0.16 | 1.0.27 |
5253
| monolog/monolog | 1.17.2 | 1.21.0 |
5354
| symfony/polyfill-mbstring | NEW | v1.2.0 |
54-
+---------------------------------------------------------+
55-
+------------------------------------------------------------+
55+
+----------------------------------+------------+---------+
56+
57+
+-----------------------------------+-----------+------------+
58+
| Dev Changes | From | To |
59+
+-----------------------------------+-----------+------------+
60+
| behat/behat | v3.0.15 | v3.2.1 |
61+
| behat/gherkin | v4.4.1 | v4.4.4 |
62+
| behat/mink | v1.7.0 | v1.7.1 |
63+
| behat/mink-browserkit-driver | v1.3.0 | v1.3.2 |
64+
| behat/mink-extension | v2.1.0 | v2.2 |
65+
| behat/mink-selenium2-driver | v1.3.0 | v1.3.1 |
66+
| mockery/mockery | 0.9.4 | REMOVED |
67+
+-----------------------------------+-----------+------------+
68+
```
69+
70+
Markdown Table
71+
==============
72+
73+
### Raw
74+
75+
```
76+
| Production Changes | From | To |
77+
|----------------------------------|------------|---------|
78+
| guzzlehttp/guzzle | 6.2.0 | 6.2.1 |
79+
| hashids/hashids | 1.0.5 | 1.0.6 |
80+
| laravel/framework | v5.1.27 | v5.1.44 |
81+
| league/flysystem | 1.0.16 | 1.0.27 |
82+
| monolog/monolog | 1.17.2 | 1.21.0 |
83+
| symfony/polyfill-mbstring | NEW | v1.2.0 |
84+
5685
| Dev Changes | From | To |
57-
+------------------------------------------------------------+
86+
|-----------------------------------|-----------|------------|
5887
| behat/behat | v3.0.15 | v3.2.1 |
5988
| behat/gherkin | v4.4.1 | v4.4.4 |
6089
| behat/mink | v1.7.0 | v1.7.1 |
6190
| behat/mink-browserkit-driver | v1.3.0 | v1.3.2 |
6291
| behat/mink-extension | v2.1.0 | v2.2 |
6392
| behat/mink-selenium2-driver | v1.3.0 | v1.3.1 |
6493
| mockery/mockery | 0.9.4 | REMOVED |
65-
+------------------------------------------------------------+
6694
```
95+
96+
### Rendered
97+
98+
| Production Changes | From | To |
99+
|----------------------------------|------------|---------|
100+
| guzzlehttp/guzzle | 6.2.0 | 6.2.1 |
101+
| hashids/hashids | 1.0.5 | 1.0.6 |
102+
| laravel/framework | v5.1.27 | v5.1.44 |
103+
| league/flysystem | 1.0.16 | 1.0.27 |
104+
| monolog/monolog | 1.17.2 | 1.21.0 |
105+
| symfony/polyfill-mbstring | NEW | v1.2.0 |
106+
107+
| Dev Changes | From | To |
108+
|-----------------------------------|-----------|------------|
109+
| behat/behat | v3.0.15 | v3.2.1 |
110+
| behat/gherkin | v4.4.1 | v4.4.4 |
111+
| behat/mink | v1.7.0 | v1.7.1 |
112+
| behat/mink-browserkit-driver | v1.3.0 | v1.3.2 |
113+
| behat/mink-extension | v2.1.0 | v2.2 |
114+
| behat/mink-selenium2-driver | v1.3.0 | v1.3.1 |
115+
| mockery/mockery | 0.9.4 | REMOVED |

composer-lock-diff

+23-8
Original file line numberDiff line numberDiff line change
@@ -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

1820
function 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

8497
function maxLength(array $array) {
@@ -141,7 +154,7 @@ function mustDecodeJson($json, $context) {
141154
}
142155

143156
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'));
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
179194
EOF;
180195

0 commit comments

Comments
 (0)