Skip to content

Commit

Permalink
actions: Made --help a global option and added handling to each of …
Browse files Browse the repository at this point in the history
…the action handlers for it
  • Loading branch information
dragonmux committed Jan 9, 2024
1 parent 484c188 commit af8dcd2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/actions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <substrate/console>
#include <substrate/units>
#include "actions.hxx"
#include "options.hxx"
#include "flashVendors.hxx"
#include "sfdp.hxx"
#include "provisionELF.hxx"
Expand Down Expand Up @@ -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<flag_t>(*sfdpArguments["bus"sv]))};
// If we got good comms, then try and identify the Flash
Expand All @@ -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
Expand Down Expand Up @@ -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<flag_t>(*readArguments["bus"sv]))};
// If we got good comms, then try and identify the Flash
Expand Down Expand Up @@ -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<flag_t>(*writeArguments["bus"sv]))};
// If we got good comms, then try and identify the Flash
Expand Down
3 changes: 2 additions & 1 deletion src/include/options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit af8dcd2

Please sign in to comment.