Skip to content

Commit

Permalink
Validate options in test_old
Browse files Browse the repository at this point in the history
Regularly try to use this one with --version instead of
--php-version, which fails in a non-obvious way.
  • Loading branch information
nikic committed Aug 11, 2024
1 parent 514f710 commit 4a22c15
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test_old/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function showHelp($error) {
);
}

$allowedOptions = [
'--no-progress' => true,
'--verbose' => true,
'--php-version' => true,
];

$options = array();
$arguments = array();

Expand All @@ -35,7 +41,11 @@ function showHelp($error) {
foreach ($argv as $arg) {
if ('-' === $arg[0]) {
$parts = explode('=', $arg);
$options[$parts[0]] = $parts[1] ?? true;
$name = $parts[0];
if (!isset($allowedOptions[$name])) {
showHelp("Unknown option \"$name\"");
}
$options[$name] = $parts[1] ?? true;
} else {
$arguments[] = $arg;
}
Expand Down

0 comments on commit 4a22c15

Please sign in to comment.