Browse Source

keep -n from consuming a parameter

naelstrof 7 years ago
parent
commit
359b426b89
3 changed files with 14 additions and 3 deletions
  1. 1
    1
      CMakeLists.txt
  2. 3
    0
      src/main.cpp
  3. 10
    2
      src/options.cpp

+ 1
- 1
CMakeLists.txt View File

21
 
21
 
22
 include_directories("${PROJECT_BINARY_DIR}")
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
 # The names have to be unique unfortunately.
26
 # The names have to be unique unfortunately.
27
 set(EXECUTABLE_NAME "slop")
27
 set(EXECUTABLE_NAME "slop")

+ 3
- 0
src/main.cpp View File

50
     } catch( ... ) {
50
     } catch( ... ) {
51
         options.getInt("nodecorations", 'n', foo->nodecorations);
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
     return foo;
56
     return foo;
54
 }
57
 }
55
 
58
 

+ 10
- 2
src/options.cpp View File

1
 #include "options.hpp"
1
 #include "options.hpp"
2
 
2
 
3
 Options::Options( int argc, char** argv ) {
3
 Options::Options( int argc, char** argv ) {
4
+    validArguments.push_back( Argument( "nodecorations", 'n', true ) );
4
     validArguments.push_back( Argument( "bordersize",   'b', false ) );
5
     validArguments.push_back( Argument( "bordersize",   'b', false ) );
5
     validArguments.push_back( Argument( "padding",      'p', false ) );
6
     validArguments.push_back( Argument( "padding",      'p', false ) );
6
     validArguments.push_back( Argument( "color",        'c', false ) );
7
     validArguments.push_back( Argument( "color",        'c', false ) );
8
     validArguments.push_back( Argument( "highlight",    'l', true ) );
9
     validArguments.push_back( Argument( "highlight",    'l', true ) );
9
     validArguments.push_back( Argument( "format",       'f', false ) );
10
     validArguments.push_back( Argument( "format",       'f', false ) );
10
     validArguments.push_back( Argument( "tolerance",    't', false ) );
11
     validArguments.push_back( Argument( "tolerance",    't', false ) );
11
-    validArguments.push_back( Argument( "nodecorations", 'n', false ) );
12
     validArguments.push_back( Argument( "nokeyboard",   'k', true ) );
12
     validArguments.push_back( Argument( "nokeyboard",   'k', true ) );
13
     validArguments.push_back( Argument( "noopengl",     'o', true ) );
13
     validArguments.push_back( Argument( "noopengl",     'o', true ) );
14
     validArguments.push_back( Argument( "help",         'h', true ) );
14
     validArguments.push_back( Argument( "help",         'h', true ) );
15
     validArguments.push_back( Argument( "xdisplay",     'x', false ) );
15
     validArguments.push_back( Argument( "xdisplay",     'x', false ) );
16
     validArguments.push_back( Argument( "version",      'v', true ) );
16
     validArguments.push_back( Argument( "version",      'v', true ) );
17
     validArguments.push_back( Argument( "quiet",        'q', true ) );
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