-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg_parser.cpp
50 lines (47 loc) · 2.2 KB
/
arg_parser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "arg_parser.h"
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
std::vector<Argument> arguments = {
{"param", "short", "", " Description"},
{"-help", "-h", "", " Prints the help and exits"},
{"-version", "-v", "", " Prints the version and exits"},
{"-monitor", "-m", "0", " 0-based index of the monitor to capture. 0 is primary"},
{"-path", "-p", ".", " Output file path, if unspecified uses your current directory"},
{"-framerate", "-fps", "-1", " Output FPS. Should match the refresh rate, which is default beahvior"},
{"-delay", "-dl", "3", " Delay (sec) before starting capture"},
{"-compression", "-comp", "0", " 1 for compressed (H.264), 0 for RGB24"},
{"-frames", "-f", "300", " Frames to capture"},
{"-duration", "-dur", "", " Duration (sec). If unspecified, uses <frames>"},
{"-queuelength", "-ql", "-1", " Length/size of queue. How many frames can be buffered before writing. -1 means FPS/2"},
{"-queuethreshold", "-qt", "-1", " Controls how many frames in the queue before it is swapped to write queue"},
{"-vfr", "-vfr", "0", " Enable variable framerate path"},
};
std::map<std::string, std::string> parseArgs(int argc, char* argv[]) {
std::map<std::string, std::string> argMap;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
// Check if argument is in our list of valid arguments
auto it = std::find_if(arguments.begin(), arguments.end(), [&arg](const Argument& a) {
return a.name == arg || a.shortName == arg;
});
if (it != arguments.end() && i + 1 < argc && argv[i + 1][0] != '-') {
argMap[it->name] = argv[++i];
}
else if (it != arguments.end()) {
argMap[it->name] = "";
}
}
return argMap;
}
std::string generateHelpText() {
std::ostringstream oss;
for (const auto& arg : arguments) {
oss << std::setw(23) << std::left << arg.name + " (" + arg.shortName + "):"
<< "Default: " << std::setw(5) << (arg.defaultValue.empty() ? "N/A" : arg.defaultValue)
<< "|" << arg.description << "\n";
}
std::cout << "link to wiki. SoonTM.." << std::endl;
return oss.str();
}