Browse Source

added version flag

naelstrof 7 years ago
parent
commit
bf24bc367c
4 changed files with 12 additions and 7 deletions
  1. 2
    0
      CMakeLists.txt
  2. 4
    0
      src/main.cpp
  3. 2
    2
      src/options.cpp
  4. 4
    5
      src/options.hpp

+ 2
- 0
CMakeLists.txt View File

1
 #Change this if you need to target a specific CMake version
1
 #Change this if you need to target a specific CMake version
2
 cmake_minimum_required(VERSION 3.1)
2
 cmake_minimum_required(VERSION 3.1)
3
 
3
 
4
+add_definitions(-DSLOP_VERSION="v5.3.21")
5
+
4
 if(NOT CMAKE_BUILD_TYPE)
6
 if(NOT CMAKE_BUILD_TYPE)
5
   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
7
   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
6
 endif()
8
 endif()

+ 4
- 0
src/main.cpp View File

155
         printHelp();
155
         printHelp();
156
         return 0;
156
         return 0;
157
     }
157
     }
158
+    if ( options.getBool( "version", 'v', help ) ) {
159
+        std::cout << SLOP_VERSION << "\n";
160
+        return 0;
161
+    }
158
     // We then parse the options into something slop can understand.
162
     // We then parse the options into something slop can understand.
159
     SlopOptions* parsedOptions = getOptions( options );
163
     SlopOptions* parsedOptions = getOptions( options );
160
 
164
 

+ 2
- 2
src/options.cpp View File

13
                 if ( !isFlagArgument[index] && argument.find("=") == std::string::npos ) {
13
                 if ( !isFlagArgument[index] && argument.find("=") == std::string::npos ) {
14
                     throw new std::invalid_argument("Expected `=` after " + arguments[i]);
14
                     throw new std::invalid_argument("Expected `=` after " + arguments[i]);
15
                 }
15
                 }
16
-                if ( argument[i+3] != '=' ) {
17
-                    break;
16
+                if ( isFlagArgument[index] && i+3 != argument.length() ) {
17
+                    throw new std::invalid_argument("Trailing characters on flag " + argument );
18
                 }
18
                 }
19
                 return parseStringOption( argc, argv, argumentIndex, index );
19
                 return parseStringOption( argc, argv, argumentIndex, index );
20
             }
20
             }

+ 4
- 5
src/options.hpp View File

28
 #include <vector>
28
 #include <vector>
29
 #include <glm/glm.hpp>
29
 #include <glm/glm.hpp>
30
 
30
 
31
-static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format", "tolerance", "nodecorations", "nokeyboard", "help", "xdisplay" };
32
-static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f', 't', 'n', 'k', 'h', 'x' };
33
-// 0 for flag, 1 for how many arguments to eat up
34
-static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, true, true, true, false};
35
-static unsigned int validArgumentCount = 11;
31
+static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format", "tolerance", "nodecorations", "nokeyboard", "help", "xdisplay", "version" };
32
+static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f', 't', 'n', 'k', 'h', 'x', 'v' };
33
+static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, true, true, true, false, true };
34
+static unsigned int validArgumentCount = 12;
36
 static unsigned int maxFloatingValues = 0;
35
 static unsigned int maxFloatingValues = 0;
37
 
36
 
38
 class Options {
37
 class Options {