From 6d14813840d163c76f6dc25395b0007a88b42e9d Mon Sep 17 00:00:00 2001 From: Kasimir Cash Date: Wed, 17 Jan 2024 07:42:43 +0000 Subject: Standardise command line option parsing (#6036) * Separates long & short options for parsing * Adds parsing for short options + doc rewrites * Fixes undefined constant in check.translation * Standardises CL option parsing * Refactors option parsing * Renames getLongOptions -> getOptions * Removes unused code * Converges on string typing for options * Updates docs & help files * Updates array syntax array( ) -> [ ] --- cli/check.translation.php | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'cli/check.translation.php') diff --git a/cli/check.translation.php b/cli/check.translation.php index 747a35be9..10a346dee 100755 --- a/cli/check.translation.php +++ b/cli/check.translation.php @@ -1,28 +1,45 @@ #!/usr/bin/env php load()); -/** @var array|false $options */ -$options = getopt('dhl:r'); - -if (!is_array($options) || array_key_exists('h', $options)) { +$parameters = [ + 'long' => [ + 'display-result' => '', + 'help' => '', + 'language' => ':', + 'display-report' => '', + ], + 'short' => [ + 'display-result' => 'd', + 'help' => 'h', + 'language' => 'l', + 'display-report' => 'r', + ], + 'deprecated' => [], +]; + +$options = parseCliParams($parameters); + +if (!empty($options['invalid']) || array_key_exists('help', $options['valid'])) { checkHelp(); } -if (array_key_exists('l', $options)) { - $languages = array($options['l']); +if (array_key_exists('language', $options['valid'])) { + $languages = [$options['valid']['language']]; } else { $languages = $i18nData->getAvailableLanguages(); } -$displayResults = array_key_exists('d', $options); -$displayReport = array_key_exists('r', $options); +$displayResults = array_key_exists('display-result', $options['valid']); +$displayReport = array_key_exists('display-report', $options['valid']); $isValidated = true; $result = []; @@ -99,10 +116,10 @@ SYNOPSIS DESCRIPTION Check if translation files have missing keys or missing translations. - -d display results. - -h display this help and exit. - -l=LANG filter by LANG. - -r display completion report. + -d, --display-result display results. + -h, --help display this help and exit. + -l, --language=LANG filter by LANG. + -r, --display-report display completion report. HELP; exit; -- cgit v1.2.3