Pārlūkot izejas kodu

keep -n from consuming a parameter

naelstrof 7 gadus atpakaļ
vecāks
revīzija
359b426b89
3 mainītis faili ar 14 papildinājumiem un 3 dzēšanām
  1. 1
    1
      CMakeLists.txt
  2. 3
    0
      src/main.cpp
  3. 10
    2
      src/options.cpp

+ 1
- 1
CMakeLists.txt Parādīt failu

@@ -21,7 +21,7 @@ endif()
21 21
 
22 22
 include_directories("${PROJECT_BINARY_DIR}")
23 23
 
24
-add_definitions(-DSLOP_VERSION="v5.3.32")
24
+add_definitions(-DSLOP_VERSION="v5.3.33")
25 25
 
26 26
 # The names have to be unique unfortunately.
27 27
 set(EXECUTABLE_NAME "slop")

+ 3
- 0
src/main.cpp Parādīt failu

@@ -50,6 +50,9 @@ SlopOptions* getOptions( Options& options ) {
50 50
     } catch( ... ) {
51 51
         options.getInt("nodecorations", 'n', foo->nodecorations);
52 52
     }
53
+    if ( foo->nodecorations < 0 || foo->nodecorations > 2 ) {
54
+        throw new std::invalid_argument( "--nodecorations must be between 0 and 2. Or be used as a flag." );
55
+    }
53 56
     return foo;
54 57
 }
55 58
 

+ 10
- 2
src/options.cpp Parādīt failu

@@ -1,6 +1,7 @@
1 1
 #include "options.hpp"
2 2
 
3 3
 Options::Options( int argc, char** argv ) {
4
+    validArguments.push_back( Argument( "nodecorations", 'n', true ) );
4 5
     validArguments.push_back( Argument( "bordersize",   'b', false ) );
5 6
     validArguments.push_back( Argument( "padding",      'p', false ) );
6 7
     validArguments.push_back( Argument( "color",        'c', false ) );
@@ -8,14 +9,21 @@ Options::Options( int argc, char** argv ) {
8 9
     validArguments.push_back( Argument( "highlight",    'l', true ) );
9 10
     validArguments.push_back( Argument( "format",       'f', false ) );
10 11
     validArguments.push_back( Argument( "tolerance",    't', false ) );
11
-    validArguments.push_back( Argument( "nodecorations", 'n', false ) );
12 12
     validArguments.push_back( Argument( "nokeyboard",   'k', true ) );
13 13
     validArguments.push_back( Argument( "noopengl",     'o', true ) );
14 14
     validArguments.push_back( Argument( "help",         'h', true ) );
15 15
     validArguments.push_back( Argument( "xdisplay",     'x', false ) );
16 16
     validArguments.push_back( Argument( "version",      'v', true ) );
17 17
     validArguments.push_back( Argument( "quiet",        'q', true ) );
18
-    validate( argc, argv );
18
+    try {
19
+        validate( argc, argv );
20
+    } catch( ... ) {
21
+        arguments.clear();
22
+        values.clear();
23
+        floatingValues.clear();
24
+        validArguments[0].isFlagArgument = false;
25
+        validate( argc, argv );
26
+    }
19 27
 }
20 28
 
21 29