diff options
| author | 2024-01-17 07:42:43 +0000 | |
|---|---|---|
| committer | 2024-01-17 08:42:43 +0100 | |
| commit | 6d14813840d163c76f6dc25395b0007a88b42e9d (patch) | |
| tree | d01fccbd7e31f4fdccfc6649621ba1d8d75a9eef /cli/user-info.php | |
| parent | 314077a457f04cc2f0472e036af029e2676fbf02 (diff) | |
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( ) -> [ ]
Diffstat (limited to 'cli/user-info.php')
| -rwxr-xr-x | cli/user-info.php | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/cli/user-info.php b/cli/user-info.php index fbf60482a..f492d26b2 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -5,37 +5,45 @@ require(__DIR__ . '/_cli.php'); const DATA_FORMAT = "%-7s | %-20s | %-5s | %-7s | %-25s | %-15s | %-10s | %-10s | %-10s | %-10s | %-10s | %-10s | %-5s | %-10s\n"; -$params = array( - 'user:', - 'header', - 'json', -); -$options = getopt('h', $params); +$parameters = [ + 'long' => [ + 'user' => ':', + 'header' => '', + 'json' => '', + 'human-readable' => '', + ], + 'short' => [ + 'human-readable' => 'h', + ], + 'deprecated' => [], +]; -if (!validateOptions($argv, $params)) { - fail('Usage: ' . basename(__FILE__) . ' (-h --header --json --user username --user username …)'); +$options = parseCliParams($parameters); + +if (!empty($options['invalid'])) { + fail('Usage: ' . basename(__FILE__) . ' (--human-readable --header --json --user username --user username …)'); } -if (empty($options['user'])) { +if (empty($options['valid']['user'])) { $users = listUsers(); -} elseif (is_array($options['user'])) { +} elseif (is_array($options['valid']['user'])) { /** @var array<string> $users */ - $users = $options['user']; + $users = $options['valid']['user']; } else { /** @var array<string> $users */ - $users = array($options['user']); + $users = [$options['valid']['user']]; } sort($users); -$formatJson = isset($options['json']); +$formatJson = isset($options['valid']['json']); $jsonOutput = []; if ($formatJson) { - unset($options['header']); - unset($options['h']); + unset($options['valid']['header']); + unset($options['valid']['human-readable']); } -if (array_key_exists('header', $options)) { +if (array_key_exists('header', $options['valid'])) { printf( DATA_FORMAT, 'default', @@ -84,7 +92,7 @@ foreach ($users as $username) { 'lang' => FreshRSS_Context::userConf()->language, 'mail_login' => FreshRSS_Context::userConf()->mail_login, ); - if (isset($options['h'])) { //Human format + if (isset($options['valid']['human-readable'])) { //Human format $data['last_user_activity'] = date('c', $data['last_user_activity']); $data['database_size'] = format_bytes($data['database_size']); } |
