MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / parse_run_parameters

Function parse_run_parameters

OpenHD/main.cpp:83–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81};
82
83static OHDRunOptions parse_run_parameters(int argc, char *argv[]) {
84 OHDRunOptions ret{};
85 int c;
86 // If this value gets set, we assume a developer is working on OpenHD and skip
87 // the discovery via file(s).
88 std::optional<bool> commandline_air = std::nullopt;
89 while ((c = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) {
90 const char *tmp_optarg = optarg;
91 switch (c) {
92 case 'a':
93 if (commandline_air != std::nullopt) {
94 // Already set, e.g. --ground is already used
95 std::cerr << "Please use either air or ground as param\n";
96 exit(1);
97 }
98 commandline_air = true;
99 break;
100 case 'g':
101 // Already set, e.g. --air is already used
102 if (commandline_air != std::nullopt) {
103 std::cerr << "Please use either air or ground as param\n";
104 exit(1);
105 }
106 commandline_air = false;
107 break;
108 case 'c':
109 ret.reset_all_settings = true;
110 break;
111 case 'w':
112 ret.no_qopenhd_autostart = true;
113 break;
114 case 'r':
115 ret.run_time_seconds = atoi(tmp_optarg);
116 break;
117 case 'h':
118 ret.hardware_config_file = tmp_optarg;
119 break;
120 case '?':
121 default: {
122 std::stringstream ss;
123 ss << "Usage: \n";
124 ss << "--air -a [Run as air, creates dummy camera if no "
125 "camera is found] \n";
126 ss << "--ground -g [Run as ground, no camera detection] \n";
127 ss << "--clean-start -c [Wipe all persistent settings OpenHD has "
128 "written, can fix any boot issues when switching hw around] \n";
129 ss << "--no-qt-autostart [disable auto start of QOpenHD on ground] \n";
130 ss << "--run-time-seconds -r [Manually specify run time (default "
131 "infinite),for debugging] \n";
132 ss << "--hardware-config-file -h [specify path to hardware.config "
133 "file]\n";
134 ss << "Use hardware.conf for more configuration\n";
135 std::cout << ss.str() << std::flush;
136 }
137 exit(1);
138 }
139 }
140 if (commandline_air == std::nullopt) {

Callers 1

mainFunction · 0.85

Calls 3

file_ground_existsFunction · 0.85
file_air_existsFunction · 0.85
getConfigBasePathFunction · 0.85

Tested by

no test coverage detected