Skip to content

Commit cbf69a5

Browse files
committed
Exit in error if VCS cannot be forced
1 parent 9a1bab8 commit cbf69a5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
OPTS ?= ""
22
PHP = php
33

4-
all: test md no-links only-dev only-prod json json-pretty
4+
all: test test-help test-help-vcs-error md no-links only-dev only-prod json json-pretty
55

66
test:
77
$(PHP) ./composer-lock-diff --from test-data/composer.from.lock --to test-data/composer.to.lock $(OPTS)
88

9+
test-help:
10+
$(PHP) ./composer-lock-diff --help
11+
12+
test-help-vcs-error:
13+
$(PHP) ./composer-lock-diff --vcs UNKNOWN ; test $$? -eq 1
14+
915
md:
1016
$(MAKE) test OPTS=--md
1117

composer-lock-diff

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ function parseOpts() {
444444

445445
$vcs = array_key_exists('vcs', $given) ? $given['vcs'] : '';
446446
if ($vcs && !function_exists('vcsLoad' . ucfirst($vcs))) {
447-
error_log("Unsupported vcs '$vcs'\n");
448-
usage();
447+
error_log(sprintf("Unsupported VCS '$vcs'; supported are: '%s'\n", implode("', '", getVcses())));
448+
usage(1);
449449
}
450450

451451
return array(
@@ -462,9 +462,9 @@ function parseOpts() {
462462
);
463463
}
464464

465-
function usage() {
465+
function usage($status = 0) {
466466
$vcses = implode(', ', getVcses());
467-
print <<<EOF
467+
$help = <<<EOF
468468
Usage: composer-lock-diff [options]
469469
470470
Options:
@@ -480,11 +480,16 @@ Options:
480480
--no-links Don't include Compare links in plain text or any links in markdown
481481
--only-prod Only include changes from `packages`
482482
--only-dev Only include changes from `packages-dev`
483-
--vcs Force vcs ($vcses). Default: attempt to auto-detect
484-
483+
--vcs Force VCS ($vcses). Default: attempt to auto-detect
485484
EOF;
486485

487-
exit(0);
486+
if ($status) {
487+
error_log($help);
488+
} else {
489+
echo $help, "\n";
490+
}
491+
492+
exit($status);
488493
}
489494
# vim: ff=unix ts=4 ss=4 sr et
490495

0 commit comments

Comments
 (0)