p-ranav / structopt

Parse command line arguments by defining a struct
MIT License
457 stars 26 forks source link

Exception without try catch? #10

Closed ru108 closed 4 years ago

ru108 commented 4 years ago
#include <iostream>
#include <optional>
#include <string>

#include <structopt/app.hpp>

struct Options {
  std::string db_name;
  std::string path_files;
  std::string path_archive;
  enum class LogLevel { trace, debug, info, warn, err, critical, off };
  std::optional<LogLevel> log_level = LogLevel::debug;
};
STRUCTOPT(Options, db_name, path_files, path_archive, log_level);

int main(int argc, char* argv[]) {
  auto opts = structopt::app("test", "1.0.0.1").parse<Options>(argc, argv);

  std::cout << "Hello World!\n";
}

without parameters ./test.exe

Microsoft Visual Studio Community 2019 Version 16.7.2 VisualStudio.16.Release/16.7.2+30413.136

ru108 commented 4 years ago

I know that wrong args but... ./test.exe --db_name=qqq --path_files=rrr --path_archive=uuu infinity loop in https://github.com/p-ranav/structopt/blob/a91831305cd01863569c92c17ecb0861b2661ea5/include/structopt/app.hpp#L39-L42