CLI: exit with error status when operation has failed

This commit is contained in:
Andrew Dolgov 2022-06-10 15:39:02 +03:00
parent cf1eaeedf3
commit 25b71b90b2
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
1 changed files with 16 additions and 7 deletions

View File

@ -140,7 +140,7 @@
printf(" %s %s\n", str_pad($option, $max_key_len + 5), $help_text); printf(" %s %s\n", str_pad($option, $max_key_len + 5), $help_text);
} }
return; exit(0);
} }
if (!isset($options['daemon'])) { if (!isset($options['daemon'])) {
@ -181,7 +181,6 @@
if (isset($options["pidlock"])) { if (isset($options["pidlock"])) {
$my_pid = $options["pidlock"]; $my_pid = $options["pidlock"];
$lock_filename = "update_daemon-$my_pid.lock"; $lock_filename = "update_daemon-$my_pid.lock";
} }
Debug::log("Lock: $lock_filename"); Debug::log("Lock: $lock_filename");
@ -251,6 +250,7 @@
if (isset($options["daemon-loop"])) { if (isset($options["daemon-loop"])) {
if (!make_stampfile('update_daemon.stamp')) { if (!make_stampfile('update_daemon.stamp')) {
Debug::log("warning: unable to create stampfile\n"); Debug::log("warning: unable to create stampfile\n");
exit(1);
} }
RSSUtils::update_daemon_common(isset($options["pidlock"]) ? 50 : Config::get(Config::DAEMON_FEED_LIMIT), $options); RSSUtils::update_daemon_common(isset($options["pidlock"]) ? 50 : Config::get(Config::DAEMON_FEED_LIMIT), $options);
@ -273,7 +273,7 @@
Debug::log("Type 'yes' to continue."); Debug::log("Type 'yes' to continue.");
if (read_stdin() != 'yes') if (read_stdin() != 'yes')
exit; exit(1);
} else { } else {
Debug::log("Proceeding to update without confirmation."); Debug::log("Proceeding to update without confirmation.");
} }
@ -283,7 +283,9 @@
} }
$migrations = Config::get_migrations(); $migrations = Config::get_migrations();
$migrations->migrate(); $rc = $migrations->migrate();
exit($rc ? 0 : 1);
} else { } else {
Debug::log("Database schema is already at latest version."); Debug::log("Database schema is already at latest version.");
@ -347,7 +349,6 @@
} }
echo "Plugins marked by * are currently enabled for all users.\n"; echo "Plugins marked by * are currently enabled for all users.\n";
} }
if (isset($options["debug-feed"])) { if (isset($options["debug-feed"])) {
@ -358,9 +359,9 @@
Debug::set_loglevel(Debug::LOG_EXTENDED); Debug::set_loglevel(Debug::LOG_EXTENDED);
$rc = RSSUtils::update_rss_feed($feed) != false ? 0 : 1; $rc = RSSUtils::update_rss_feed($feed);
exit($rc); exit($rc ? 0 : 1);
} }
if (isset($options["send-digests"])) { if (isset($options["send-digests"])) {
@ -389,8 +390,10 @@
$rc = $opml->opml_export($filename, $owner_uid, false, true, true); $rc = $opml->opml_export($filename, $owner_uid, false, true, true);
Debug::log($rc ? "Success." : "Failed."); Debug::log($rc ? "Success." : "Failed.");
exit($rc ? 0 : 1);
} else { } else {
Debug::log("User not found: $user"); Debug::log("User not found: $user");
exit(1);
} }
} }
@ -405,8 +408,10 @@
$rc = $opml->opml_import($owner_uid, $filename); $rc = $opml->opml_import($owner_uid, $filename);
Debug::log($rc ? "Success." : "Failed."); Debug::log($rc ? "Success." : "Failed.");
exit($rc ? 0 : 1);
} else { } else {
Debug::log("User not found: $user"); Debug::log("User not found: $user");
exit(1);
} }
} }
@ -445,6 +450,7 @@
Debug::log("Success."); Debug::log("Success.");
} else { } else {
Debug::log("Operation failed, check the logs for more information."); Debug::log("Operation failed, check the logs for more information.");
exit(1);
} }
} }
@ -464,6 +470,7 @@
Debug::log("Success."); Debug::log("Success.");
} else { } else {
Debug::log("Operation failed, check the logs for more information."); Debug::log("Operation failed, check the logs for more information.");
exit(1);
} }
} }
@ -488,6 +495,7 @@
Debug::log("Success."); Debug::log("Success.");
} else { } else {
Debug::log("Operation failed, check the logs for more information."); Debug::log("Operation failed, check the logs for more information.");
exit(1);
} }
} }
@ -514,6 +522,7 @@
Debug::log("Success."); Debug::log("Success.");
} else { } else {
Debug::log("Operation failed, check the logs for more information."); Debug::log("Operation failed, check the logs for more information.");
exit(1);
} }
} }