Amending CLI code for "All Devices" to resolve #2918

* Adding `current_devices->size() == 0` check to Mode / Color / Brightness argument parsers to catch "All Devices" case from CLI
This commit is contained in:
Chris 2022-12-02 20:35:19 +11:00 committed by Adam Honse
parent a0024b8f04
commit 5abc13e7df

67
cli.cpp
View file

@ -641,30 +641,47 @@ bool OptionZone(std::vector<DeviceOptions>* current_devices, std::string argumen
return found;
}
bool OptionColor(std::vector<DeviceOptions>* current_devices, std::string argument, Options* /*options*/)
bool CheckColor(std::string argument, DeviceOptions* currentDevOpts)
{
bool found = false;
for(size_t i = 0; i < current_devices->size(); i++)
{
DeviceOptions* currentDevOpts = &current_devices->at(i);
if(ParseColors(argument, currentDevOpts))
{
currentDevOpts->hasOption = true;
found = true;
return true;
}
else
{
std::cout << "Error: Invalid color value: " + argument << std::endl;
return false;
}
}
bool OptionColor(std::vector<DeviceOptions>* current_devices, std::string argument, Options* options)
{
/*---------------------------------------------------------*\
| If a device is not selected i.e. size() == 0 |
| then add color to allDeviceOptions |
\*---------------------------------------------------------*/
bool found = false;
DeviceOptions* currentDevOpts = &options->allDeviceOptions;
if(current_devices->size() == 0)
{
found = CheckColor(argument, currentDevOpts);
}
else
{
for(size_t i = 0; i < current_devices->size(); i++)
{
currentDevOpts = &current_devices->at(i);
found = CheckColor(argument, currentDevOpts);
}
}
return found;
}
bool OptionMode(std::vector<DeviceOptions>* current_devices, std::string argument, Options* /*options*/)
bool OptionMode(std::vector<DeviceOptions>* current_devices, std::string argument, Options* options)
{
if(argument.size() == 0)
{
@ -672,21 +689,35 @@ bool OptionMode(std::vector<DeviceOptions>* current_devices, std::string argumen
return false;
}
/*---------------------------------------------------------*\
| If a device is not selected i.e. size() == 0 |
| then add mode to allDeviceOptions |
\*---------------------------------------------------------*/
bool found = false;
DeviceOptions* currentDevOpts = &options->allDeviceOptions;
if(current_devices->size() == 0)
{
currentDevOpts->mode = argument;
currentDevOpts->hasOption = true;
found = true;
}
else
{
for(size_t i = 0; i < current_devices->size(); i++)
{
DeviceOptions* currentDevOpts = &current_devices->at(i);
currentDevOpts = &current_devices->at(i);
currentDevOpts->mode = argument;
currentDevOpts->hasOption = true;
found = true;
}
}
return found;
}
bool OptionBrightness(std::vector<DeviceOptions>* current_devices, std::string argument, Options* /*options*/)
bool OptionBrightness(std::vector<DeviceOptions>* current_devices, std::string argument, Options* options)
{
if(argument.size() == 0)
{
@ -694,8 +725,21 @@ bool OptionBrightness(std::vector<DeviceOptions>* current_devices, std::string a
return false;
}
/*---------------------------------------------------------*\
| If a device is not selected i.e. size() == 0 |
| then add brightness to allDeviceOptions |
\*---------------------------------------------------------*/
bool found = false;
DeviceOptions* currentDevOpts = &options->allDeviceOptions;
if(current_devices->size() == 0)
{
currentDevOpts->brightness = std::min(std::max(std::stoi(argument), 0),(int)brightness_percentage);
currentDevOpts->hasOption = true;
found = true;
}
else
{
for(size_t i = 0; i < current_devices->size(); i++)
{
DeviceOptions* currentDevOpts = &current_devices->at(i);
@ -704,6 +748,7 @@ bool OptionBrightness(std::vector<DeviceOptions>* current_devices, std::string a
currentDevOpts->hasOption = true;
found = true;
}
}
return found;
}