From af8dcd266b6f49b3a34873f7b2e15642c6654389 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 9 Jan 2024 17:48:10 +0000 Subject: [PATCH] actions: Made `--help` a global option and added handling to each of the action handlers for it --- src/actions.cxx | 25 +++++++++++++++++++++++++ src/include/options.hxx | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/actions.cxx b/src/actions.cxx index 53c4cc1..1800d95 100644 --- a/src/actions.cxx +++ b/src/actions.cxx @@ -10,6 +10,7 @@ #include #include #include "actions.hxx" +#include "options.hxx" #include "flashVendors.hxx" #include "sfdp.hxx" #include "provisionELF.hxx" @@ -181,6 +182,12 @@ namespace bmpflash bool displaySFDP(const usbDevice_t &device, const arguments_t &sfdpArguments) { + // Check if help was asked for and handle that if it was + if (sfdpArguments["help"sv]) + { + sfdpOptions.displayHelp(); + return true; + } // Try to begin communications with the BMP auto probe{beginComms(device, std::get(*sfdpArguments["bus"sv]))}; // If we got good comms, then try and identify the Flash @@ -194,6 +201,12 @@ namespace bmpflash bool provision(const usbDevice_t &device, const arguments_t &provisionArguments) { + // Check if help was asked for and handle that if it was + if (provisionArguments["help"sv]) + { + provisioningOptions.displayHelp(); + return true; + } // Try to begin communications with the BMP auto probe{beginComms(device, spiBus_t::internal)}; // If we got good comms, then try and identify the Flash @@ -222,6 +235,12 @@ namespace bmpflash bool read(const usbDevice_t &device, const arguments_t &readArguments) { + // Check if help was asked for and handle that if it was + if (readArguments["help"sv]) + { + generalFlashOptions.displayHelp(); + return true; + } // Try to begin communications with the BMP auto probe{beginComms(device, std::get(*readArguments["bus"sv]))}; // If we got good comms, then try and identify the Flash @@ -269,6 +288,12 @@ namespace bmpflash bool write(const usbDevice_t &device, const arguments_t &writeArguments) { + // Check if help was asked for and handle that if it was + if (writeArguments["help"sv]) + { + generalFlashOptions.displayHelp(); + return true; + } // Try to begin communications with the BMP auto probe{beginComms(device, std::get(*writeArguments["bus"sv]))}; // If we got good comms, then try and identify the Flash diff --git a/src/include/options.hxx b/src/include/options.hxx index e228bb7..212d0e5 100644 --- a/src/include/options.hxx +++ b/src/include/options.hxx @@ -111,7 +111,8 @@ namespace bmpflash { options ( - option_t{optionFlagPair_t{"-h"sv, "--help"sv}, "Display this help message and exit"sv}.exclusive(), + option_t{optionFlagPair_t{"-h"sv, "--help"sv}, "Display this help message and exit"sv} + .exclusive().global(), option_t{"--version"sv, "Display the program version information and exit"sv}.exclusive(), option_t{optionFlagPair_t{"-v"sv, "--verbosity"sv}, "Set the program output verbosity"sv} .takesParameter(optionValueType_t::unsignedInt).valueRange(0U, 1U),