From 075905f7ea8acaa910a267553ef6c94e94097bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Mon, 29 Jul 2019 17:23:38 +0200 Subject: [PATCH] Take exception to exceptions to handle argparser errors and help --- NuEVI/settings.h | 3 ++- simulation/src/nuevisim.cpp | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/NuEVI/settings.h b/NuEVI/settings.h index c1ba891..31ceee8 100644 --- a/NuEVI/settings.h +++ b/NuEVI/settings.h @@ -133,7 +133,8 @@ void sendSysexSettings(); void sendSysexMessage(const char* messageCode); void sendSysexVersion(); -void handleSysex(uint8_t *data, uint8_t length); +void handleSysex(const uint8_t *data, uint8_t length); +void handleSysexChunk(const uint8_t *data, uint16_t length, bool last); uint32_t crc32(uint8_t *message, size_t length); void configInitScreen(); diff --git a/simulation/src/nuevisim.cpp b/simulation/src/nuevisim.cpp index 305121f..127163f 100644 --- a/simulation/src/nuevisim.cpp +++ b/simulation/src/nuevisim.cpp @@ -1,5 +1,6 @@ #include #include +#include #include @@ -16,6 +17,7 @@ #include +#define ARGS_NOEXCEPT #include "args.hxx" // Forward declarations @@ -622,10 +624,10 @@ static void SimQuit() int main(int argc, const char** argv) { - args::ArgumentParser parser("This is a test program.", "This goes after the options."); + args::ArgumentParser parser("NuEVI simulator."); - - args::ValueFlag eepromFile(parser, "eeprom-write", "File to use for EEPROM data", {'e', "eeprom-file"}); + args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); + args::ValueFlag eepromFile(parser, "filename", "File to use for EEPROM data", {'e', "eeprom-file"}); args::Flag eepromWrite(parser, "eeprom-write", "Write EEPROM changes to file", {'w', "eeprom-write"}); args::Flag factoryReset(parser, "factory-reset", "Trigger factory reset", {'r', "factory-reset"}); args::Flag configMode(parser, "config-mode", "Trigger config-management mode", {'c', "config-mode"}); @@ -633,6 +635,17 @@ int main(int argc, const char** argv) parser.ParseCLI(argc, argv); + if(parser.GetError() != args::Error::None) { + + if(parser.GetError() == args::Error::Help) { + std::cout << parser << std::endl; + return 0; + } + + std::cerr << parser.GetErrorMsg() << std::endl; + return 1; + } + std::string eepromFileName = args::get(eepromFile); //Use a default EEPROM file if none is provided.