From 76a5a91fe03cca7ba22685c351722181f1b8f1be Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 27 Aug 2022 13:45:00 +0200 Subject: [PATCH] Add exit codes for some failure modes --- .../src/main/java/pgp/cert_d/cli/PGPCertDCli.java | 5 ++++- .../src/main/java/pgp/cert_d/cli/commands/Get.java | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/PGPCertDCli.java b/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/PGPCertDCli.java index 7fbac8f..b22d47f 100644 --- a/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/PGPCertDCli.java +++ b/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/PGPCertDCli.java @@ -42,11 +42,14 @@ public class PGPCertDCli { static PGPainlessCertD certificateDirectory; + // https://www.cyberciti.biz/faq/linux-bash-exit-status-set-exit-statusin-bash/ + public static final int EXIT_CODE_NOT_A_STORE = 30; + private int executionStrategy(CommandLine.ParseResult parseResult) { try { initStore(); } catch (NotAStoreException | SQLException e) { - return -1; + return EXIT_CODE_NOT_A_STORE; } return new CommandLine.RunLast().execute(parseResult); } diff --git a/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/commands/Get.java b/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/commands/Get.java index 3a998e8..6e35ecc 100644 --- a/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/commands/Get.java +++ b/pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli/commands/Get.java @@ -27,6 +27,10 @@ public class Get implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(Get.class); + // https://www.cyberciti.biz/faq/linux-bash-exit-status-set-exit-statusin-bash/ + public static final int EXIT_CODE_NO_SUCH_ELEMENT = 2; + public static final int EXIT_CODE_IO_ERROR = 5; + @CommandLine.Option(names = {"-a", "--armor"}) boolean armor = false; @@ -60,9 +64,10 @@ public class Get implements Runnable { } catch (NoSuchElementException e) { LOGGER.debug("Certificate not found.", e); + System.exit(EXIT_CODE_NO_SUCH_ELEMENT); } catch (IOException e) { LOGGER.error("IO Error", e); - System.exit(-1); + System.exit(EXIT_CODE_IO_ERROR); } catch (BadDataException e) { LOGGER.error("Certificate file contains bad data.", e); System.exit(-1);