mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 09:16:11 +00:00
Rearrange argument parsing for help commands
Help output does not need to initialize a device, so rearrange the parsing to check for help commands prior to performing any device IO. Signed-off-by: Kevin Pearson <pearson.kevin.m@gmail.com>
This commit is contained in:
parent
114fa9b703
commit
c19d4760ce
15
src/main.cpp
15
src/main.cpp
@ -280,19 +280,22 @@ int main(int argc, char **argv) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Commands that do not need to initialize a specific device
|
||||||
|
if (arg == "--help" || arg == "-h") {help::usage(argv[0]); return 0;}
|
||||||
|
else if (arg == "--list-keyboards") return listKeyboards(kbd);
|
||||||
|
else if (arg == "--help-keys") {help::keys(argv[0]); return 0;}
|
||||||
|
else if (arg == "--help-effects") {help::effects(argv[0]); return 0;}
|
||||||
|
else if (arg == "--help-samples") {help::samples(argv[0]); return 0;}
|
||||||
|
|
||||||
|
//Initialize the device for use
|
||||||
if (!kbd.open(vendorID, productID, serial)) {
|
if (!kbd.open(vendorID, productID, serial)) {
|
||||||
std::cout << "Matching or compatible device not found" << std::endl;
|
std::cout << "Matching or compatible device not found" << std::endl;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command arguments, these will cause parsing to ignore anything beyond the command and its arguments
|
// Command arguments, these will cause parsing to ignore anything beyond the command and its arguments
|
||||||
if (arg == "-c") return commit(kbd);
|
if (arg == "-c") return commit(kbd);
|
||||||
else if (arg == "--help" || arg == "-h") {help::usage(argv[0]); return 0;}
|
|
||||||
else if (arg == "--help-keys") {help::keys(argv[0]); return 0;}
|
|
||||||
else if (arg == "--help-effects") {help::effects(argv[0]); return 0;}
|
|
||||||
else if (arg == "--help-samples") {help::samples(argv[0]); return 0;}
|
|
||||||
else if (arg == "--list-keyboards") return listKeyboards(kbd);
|
|
||||||
else if (arg == "--print-device") {printDeviceInfo(kbd.getCurrentDevice()); return 0;}
|
else if (arg == "--print-device") {printDeviceInfo(kbd.getCurrentDevice()); return 0;}
|
||||||
|
|
||||||
else if (argc > (argIndex + 1) && arg == "-a") return setAllKeys(kbd, argv[argIndex + 1]);
|
else if (argc > (argIndex + 1) && arg == "-a") return setAllKeys(kbd, argv[argIndex + 1]);
|
||||||
else if (argc > (argIndex + 2) && arg == "-g") return setGroupKeys(kbd, argv[argIndex + 1], argv[argIndex + 2]);
|
else if (argc > (argIndex + 2) && arg == "-g") return setGroupKeys(kbd, argv[argIndex + 1], argv[argIndex + 2]);
|
||||||
else if (argc > (argIndex + 2) && arg == "-k") return setKey(kbd, argv[argIndex + 1], argv[argIndex + 2]);
|
else if (argc > (argIndex + 2) && arg == "-k") return setKey(kbd, argv[argIndex + 1], argv[argIndex + 2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user