Skip to content

Commit d3198dd

Browse files
committed
Adds flags to show only prod or dev changes
1 parent 1795530 commit d3198dd

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Or from vim, to insert the output into the commit message, type `:r!composer-loc
3737
- `--json`: json output
3838
- `--pretty`: pretty output when combined with `--json` (>=5.4 only)
3939
- `--no-links`: Don't include Compare links in plain text or any links in markdown
40+
- `--only-prod`: Only include changes from `packages`
41+
- `--only-dev`: Only include changes from `packages-dev`
4042

4143
^ File includes anything available as a [protocol stream wrapper](http://php.net/manual/en/wrappers.php) such as URLs.
4244

composer-lock-diff

+32-15
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33

44
$opts = parseOpts();
55

6-
$prod = diff('packages', $opts['from'], $opts['to'], $opts['path']);
7-
$dev = diff('packages-dev', $opts['from'], $opts['to'], $opts['path']);
6+
$changes = array();
7+
8+
if (! $opts['only-dev']) {
9+
$changes['changes'] = diff('packages', $opts['from'], $opts['to'], $opts['path']);
10+
}
11+
12+
if (! $opts['only-prod']) {
13+
$changes['changes-dev'] = diff('packages-dev', $opts['from'], $opts['to'], $opts['path']);
14+
}
815

916
if ($opts['json']) {
1017
$json_opts = ($opts['pretty']) ? JSON_PRETTY_PRINT : 0;
11-
print json_encode(array('changes' => $prod, 'changes-dev' => $dev), $json_opts);
18+
print json_encode($changes, $json_opts);
1219
return;
1320
}
1421

@@ -24,8 +31,14 @@ if ($opts['md']) {
2431
));
2532
}
2633

27-
print tableize('Production Changes', $prod, $table_opts);
28-
print tableize('Dev Changes', $dev, $table_opts);
34+
$table_titles = [
35+
'changes' => 'Production Changes',
36+
'changes-dev' => 'Dev Changes',
37+
];
38+
39+
foreach($changes as $k => $diff) {
40+
print tableize($table_titles[$k], $diff, $table_opts);
41+
}
2942

3043
function diff($key, $from, $to, $base_path) {
3144

@@ -235,7 +248,7 @@ function formatCompareGitlab($url, $from, $to) {
235248
}
236249

237250
function parseOpts() {
238-
$given = getopt('hp:', array('path:', 'from:', 'to:', 'md', 'json', 'pretty', 'no-links', 'help'));
251+
$given = getopt('hp:', array('path:', 'from:', 'to:', 'md', 'json', 'pretty', 'no-links', 'only-prod', 'only-dev', 'help'));
239252

240253
foreach(array('help' => 'h', 'path' => 'p') as $long => $short) {
241254
if (array_key_exists($short, $given)) {
@@ -256,6 +269,8 @@ function parseOpts() {
256269
'json' => array_key_exists('json', $given),
257270
'pretty' => version_compare(PHP_VERSION, '5.4.0', '>=') && array_key_exists('pretty', $given),
258271
'no-links' => array_key_exists('no-links', $given),
272+
'only-prod' => array_key_exists('only-prod', $given),
273+
'only-dev' => array_key_exists('only-dev', $given),
259274
);
260275
}
261276

@@ -264,15 +279,17 @@ function usage() {
264279
Usage: composer-lock-diff [options]
265280
266281
Options:
267-
-h --help Print this message
268-
--path, -p Base to with which to prefix paths. Default "./"
269-
E.g. `-p app` would look for HEAD:app/composer.lock and app/composer.lock
270-
--from The file, git ref, or git ref with filename to compare from (HEAD:composer.lock)
271-
--to The file, git ref, or git ref with filename to compare to (composer.lock)
272-
--json Format output as JSON
273-
--pretty Pretty print JSON output (PHP >= 5.4.0)
274-
--md Use markdown instead of plain text
275-
--no-links Don't include Compare links in plain text or any links in markdown
282+
-h --help Print this message
283+
--path, -p Base to with which to prefix paths. Default "./"
284+
E.g. `-p app` would look for HEAD:app/composer.lock and app/composer.lock
285+
--from The file, git ref, or git ref with filename to compare from (HEAD:composer.lock)
286+
--to The file, git ref, or git ref with filename to compare to (composer.lock)
287+
--json Format output as JSON
288+
--pretty Pretty print JSON output (PHP >= 5.4.0)
289+
--md Use markdown instead of plain text
290+
--no-links Don't include Compare links in plain text or any links in markdown
291+
--only-prod Only include changes from `packages`
292+
--only-dev Only include changes from `packages-dev`
276293
277294
EOF;
278295

0 commit comments

Comments
 (0)