Browse Source

slop now errors properly when a positional argument is supplied

naelstrof 7 years ago
parent
commit
ab41bb7d3c
1 changed files with 6 additions and 0 deletions
  1. 6
    0
      src/main.cpp

+ 6
- 0
src/main.cpp View File

242
     ("q,quiet", "Disable any unnecessary cerr output. Any warnings or info simply won't print.")
242
     ("q,quiet", "Disable any unnecessary cerr output. Any warnings or info simply won't print.")
243
     ("k,nokeyboard", "Disables the ability to cancel selections with the keyboard.")
243
     ("k,nokeyboard", "Disables the ability to cancel selections with the keyboard.")
244
     ("o,noopengl", "Disables graphics hardware acceleration.")
244
     ("o,noopengl", "Disables graphics hardware acceleration.")
245
+    ("positional", "Positional parameters", cxxopts::value<std::vector<std::string>>())
245
     ;
246
     ;
247
+    options.parse_positional("positional");
246
     options.parse(argc, argv);
248
     options.parse(argc, argv);
247
     // Options just validates all of our input from argv
249
     // Options just validates all of our input from argv
248
     bool quiet = false;
250
     bool quiet = false;
249
     if ( options.count( "quiet" ) > 0 ) {
251
     if ( options.count( "quiet" ) > 0 ) {
250
         quiet = options["quiet"].as<bool>();
252
         quiet = options["quiet"].as<bool>();
251
     }
253
     }
254
+    auto& positional = options["positional"].as<std::vector<std::string>>();
255
+    if ( positional.size() > 0 ) {
256
+        throw new std::invalid_argument("Unexpected positional argument: " + positional[0]);
257
+    }
252
     bool help = false;
258
     bool help = false;
253
     if ( options.count( "help" ) > 0 ) {
259
     if ( options.count( "help" ) > 0 ) {
254
         help = options["help"].as<bool>();
260
         help = options["help"].as<bool>();