diff options
| author | 2024-01-17 07:42:43 +0000 | |
|---|---|---|
| committer | 2024-01-17 08:42:43 +0100 | |
| commit | 6d14813840d163c76f6dc25395b0007a88b42e9d (patch) | |
| tree | d01fccbd7e31f4fdccfc6649621ba1d8d75a9eef /cli/import-sqlite-for-user.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/import-sqlite-for-user.php')
| -rwxr-xr-x | cli/import-sqlite-for-user.php | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/cli/import-sqlite-for-user.php b/cli/import-sqlite-for-user.php index b61a73523..29b7c1b0c 100755 --- a/cli/import-sqlite-for-user.php +++ b/cli/import-sqlite-for-user.php @@ -5,20 +5,27 @@ require(__DIR__ . '/_cli.php'); performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); -$params = [ - 'user:', - 'filename:', - 'force-overwrite', +$parameters = [ + 'long' => [ + 'user' => ':', + 'filename' => ':', + 'force-overwrite' => '', + ], + 'short' => [], + 'deprecated' => [], ]; -$options = getopt('', $params); +$options = parseCliParams($parameters); -if (!validateOptions($argv, $params) || empty($options['user']) || empty($options['filename']) || !is_string($options['user']) || !is_string($options['filename'])) { +if (!empty($options['invalid']) + || empty($options['valid']['user']) || empty($options['valid']['filename']) + || !is_string($options['valid']['user']) || !is_string($options['valid']['filename']) +) { fail('Usage: ' . basename(__FILE__) . ' --user username --force-overwrite --filename /path/to/db.sqlite'); } -$username = cliInitUser($options['user']); -$filename = $options['filename']; +$username = cliInitUser($options['valid']['user']); +$filename = $options['valid']['filename']; if (pathinfo($filename, PATHINFO_EXTENSION) !== 'sqlite') { fail('Only *.sqlite files are supported!'); @@ -27,7 +34,7 @@ if (pathinfo($filename, PATHINFO_EXTENSION) !== 'sqlite') { echo 'FreshRSS importing database from SQLite for user “', $username, "”…\n"; $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username); -$clearFirst = array_key_exists('force-overwrite', $options); +$clearFirst = array_key_exists('force-overwrite', $options['valid']); $ok = $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_IMPORT, $clearFirst); if (!$ok) { echo 'If you would like to clear the user database first, use the option --force-overwrite', "\n"; |
