Skip to content

feat: use getopt-php. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions bin/php-variable-hard-usage
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php
}
}

use GetOpt\GetOpt;
use GetOpt\Option;
use Smeghead\PhpVariableHardUsage\EntryPoint;
use Smeghead\PhpVariableHardUsage\Option\GetOptions;

$getOptions = new GetOptions($_SERVER['argv']);
$result = $getOptions->parse();
$getOpt = new GetOpt([
Option::create('h', 'help', GetOpt::NO_ARGUMENT),
Option::create('v', 'version', GetOpt::NO_ARGUMENT),
Option::create('t', 'threshold', GetOpt::REQUIRED_ARGUMENT)
->setValidation(function ($value) {
return is_numeric($value) && $value >= 0;
}, 'Threshold must be a number greater than or equal to 0'),
]);

try {
$getOpt->process();
} catch (Exception $exception) {
file_put_contents('php://stderr', 'Error: ' . $exception->getMessage() . PHP_EOL);
exit(1);
}

$entryPoint = new EntryPoint();
$exitCode = $entryPoint->run($result->options, $result->paths);
$exitCode = $entryPoint->run($getOpt->options, $getOpt->operands);
exit($exitCode);
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"require": {
"php" : ">=8.1",
"nikic/php-parser": "^5.2"
"nikic/php-parser": "^5.2",
"ulrichsg/getopt-php": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
Expand Down
47 changes: 0 additions & 47 deletions src/Option/GetOptions.php

This file was deleted.

61 changes: 0 additions & 61 deletions test/GetOptionsTest.php

This file was deleted.