Skip to content

Commit 60a33af

Browse files
committed
Fix validation of CLI arguments when a target manual directory has to be provided
Additionally, let's make sure that we don't try to process the stub files in the manual target directory. This comes with a slight performance benefit.
1 parent 36b7692 commit 60a33af

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

build/gen_stub.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5143,23 +5143,33 @@ function initPhpParser() {
51435143
$context->forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
51445144
$context->forceParse = $context->forceRegeneration || $printParameterStats || $verify || $verifyManual || $replacePredefinedConstants || $generateClassSynopses || $generateOptimizerInfo || $replaceClassSynopses || $generateMethodSynopses || $replaceMethodSynopses;
51455145

5146-
$manualTarget = $argv[$argc - 1] ?? null;
5147-
if (($replacePredefinedConstants || $verifyManual) && $manualTarget === null) {
5148-
die("A target manual directory must be provided.\n");
5146+
if (isset($options["h"]) || isset($options["help"])) {
5147+
die("\nUsage: gen_stub.php [ -f | --force-regeneration ] [ --replace-predefined-constants ] [ --generate-classsynopses ] [ --replace-classsynopses ] [ --generate-methodsynopses ] [ --replace-methodsynopses ] [ --parameter-stats ] [ --verify ] [ --verify-manual ] [ --generate-optimizer-info ] [ -h | --help ] [ name.stub.php | directory ] [ directory ]\n\n");
51495148
}
5150-
if (($replaceClassSynopses || $verifyManual) && $manualTarget === null) {
5151-
die("A target manual directory must be provided.\n");
5149+
5150+
$locations = array_slice($argv, $optind);
5151+
$locationCount = count($locations);
5152+
if ($replacePredefinedConstants && $locationCount < 2) {
5153+
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-predefined-constants ./ ../doc-en/\n");
51525154
}
5153-
if (($replaceMethodSynopses || $verifyManual) && $manualTarget === null) {
5154-
die("A target manual directory must be provided.\n");
5155+
if ($replaceClassSynopses && $locationCount < 2) {
5156+
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-classsynopses ./ ../doc-en/\n");
51555157
}
5156-
5157-
if (isset($options["h"]) || isset($options["help"])) {
5158-
die("\nUsage: gen_stub.php [ -f | --force-regeneration ] [ --replace-predefined-constants ] [ --generate-classsynopses ] [ --replace-classsynopses ] [ --generate-methodsynopses ] [ --replace-methodsynopses ] [ --parameter-stats ] [ --verify ] [ --verify-manual ] [ --generate-optimizer-info ] [ -h | --help ] [ name.stub.php | directory ] [ directory ]\n\n");
5158+
if ($replaceMethodSynopses && $locationCount < 2) {
5159+
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --replace-methodsynopses ./ ../doc-en/\n");
5160+
}
5161+
if ($verifyManual && $locationCount < 2) {
5162+
die("At least one source stub path and a target manual directory has to be provided:\n./build/gen_stub.php --verify-manual ./ ../doc-en/\n");
5163+
}
5164+
$manualTarget = null;
5165+
if ($replacePredefinedConstants || $replaceClassSynopses || $replaceMethodSynopses || $verifyManual) {
5166+
$manualTarget = array_pop($locations);
5167+
}
5168+
if ($locations === []) {
5169+
$locations = ['.'];
51595170
}
51605171

51615172
$fileInfos = [];
5162-
$locations = array_slice($argv, $optind) ?: ['.'];
51635173
foreach (array_unique($locations) as $location) {
51645174
if (is_file($location)) {
51655175
// Generate single file.

0 commit comments

Comments
 (0)