3
3
4
4
$ opts = parseOpts ();
5
5
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
+ }
8
15
9
16
if ($ opts ['json ' ]) {
10
17
$ 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 );
12
19
return ;
13
20
}
14
21
@@ -24,8 +31,14 @@ if ($opts['md']) {
24
31
));
25
32
}
26
33
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
+ }
29
42
30
43
function diff ($ key , $ from , $ to , $ base_path ) {
31
44
@@ -235,7 +248,7 @@ function formatCompareGitlab($url, $from, $to) {
235
248
}
236
249
237
250
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 ' ));
239
252
240
253
foreach (array ('help ' => 'h ' , 'path ' => 'p ' ) as $ long => $ short ) {
241
254
if (array_key_exists ($ short , $ given )) {
@@ -256,6 +269,8 @@ function parseOpts() {
256
269
'json ' => array_key_exists ('json ' , $ given ),
257
270
'pretty ' => version_compare (PHP_VERSION , '5.4.0 ' , '>= ' ) && array_key_exists ('pretty ' , $ given ),
258
271
'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 ),
259
274
);
260
275
}
261
276
@@ -264,15 +279,17 @@ function usage() {
264
279
Usage: composer-lock-diff [options]
265
280
266
281
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`
276
293
277
294
EOF ;
278
295
0 commit comments