Take exception to exceptions to handle argparser errors and help

This commit is contained in:
John Stäck 2019-07-29 17:23:38 +02:00
parent 2741ff5a27
commit 075905f7ea
2 changed files with 18 additions and 4 deletions

View file

@ -133,7 +133,8 @@ void sendSysexSettings();
void sendSysexMessage(const char* messageCode); void sendSysexMessage(const char* messageCode);
void sendSysexVersion(); 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); uint32_t crc32(uint8_t *message, size_t length);
void configInitScreen(); void configInitScreen();

View file

@ -1,5 +1,6 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include <iostream>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@ -16,6 +17,7 @@
#include <Arduino.h> #include <Arduino.h>
#define ARGS_NOEXCEPT
#include "args.hxx" #include "args.hxx"
// Forward declarations // Forward declarations
@ -622,10 +624,10 @@ static void SimQuit()
int main(int argc, const char** argv) 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::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
args::ValueFlag<std::string> eepromFile(parser, "eeprom-write", "File to use for EEPROM data", {'e', "eeprom-file"}); args::ValueFlag<std::string> 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 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 factoryReset(parser, "factory-reset", "Trigger factory reset", {'r', "factory-reset"});
args::Flag configMode(parser, "config-mode", "Trigger config-management mode", {'c', "config-mode"}); 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); 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); std::string eepromFileName = args::get(eepromFile);
//Use a default EEPROM file if none is provided. //Use a default EEPROM file if none is provided.