Sfoglia il codice sorgente

added version flag

naelstrof 7 anni fa
parent
commit
bf24bc367c
4 ha cambiato i file con 12 aggiunte e 7 eliminazioni
  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 Vedi File

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

+ 4
- 0
src/main.cpp Vedi File

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

+ 2
- 2
src/options.cpp Vedi File

@@ -13,8 +13,8 @@ int Options::validateStringOption( int argc, char** argv, int argumentIndex ) {
13 13
                 if ( !isFlagArgument[index] && argument.find("=") == std::string::npos ) {
14 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 19
                 return parseStringOption( argc, argv, argumentIndex, index );
20 20
             }

+ 4
- 5
src/options.hpp Vedi File

@@ -28,11 +28,10 @@
28 28
 #include <vector>
29 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 35
 static unsigned int maxFloatingValues = 0;
37 36
 
38 37
 class Options {