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:
parent
a0024b8f04
commit
5abc13e7df
1 changed files with 70 additions and 25 deletions
95
cli.cpp
95
cli.cpp
|
|
@ -641,30 +641,47 @@ bool OptionZone(std::vector<DeviceOptions>* current_devices, std::string argumen
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OptionColor(std::vector<DeviceOptions>* current_devices, std::string argument, Options* /*options*/)
|
bool CheckColor(std::string argument, DeviceOptions* currentDevOpts)
|
||||||
{
|
{
|
||||||
bool found = false;
|
if(ParseColors(argument, currentDevOpts))
|
||||||
|
|
||||||
for(size_t i = 0; i < current_devices->size(); i++)
|
|
||||||
{
|
{
|
||||||
DeviceOptions* currentDevOpts = ¤t_devices->at(i);
|
currentDevOpts->hasOption = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Error: Invalid color value: " + argument << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(ParseColors(argument, currentDevOpts))
|
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->hasOption = true;
|
currentDevOpts = ¤t_devices->at(i);
|
||||||
found = true;
|
|
||||||
}
|
found = CheckColor(argument, currentDevOpts);
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Error: Invalid color value: " + argument << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
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)
|
if(argument.size() == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -672,21 +689,35 @@ bool OptionMode(std::vector<DeviceOptions>* current_devices, std::string argumen
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = false;
|
/*---------------------------------------------------------*\
|
||||||
|
| If a device is not selected i.e. size() == 0 |
|
||||||
|
| then add mode to allDeviceOptions |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
bool found = false;
|
||||||
|
DeviceOptions* currentDevOpts = &options->allDeviceOptions;
|
||||||
|
|
||||||
for(size_t i = 0; i < current_devices->size(); i++)
|
if(current_devices->size() == 0)
|
||||||
{
|
{
|
||||||
DeviceOptions* currentDevOpts = ¤t_devices->at(i);
|
|
||||||
|
|
||||||
currentDevOpts->mode = argument;
|
currentDevOpts->mode = argument;
|
||||||
currentDevOpts->hasOption = true;
|
currentDevOpts->hasOption = true;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < current_devices->size(); i++)
|
||||||
|
{
|
||||||
|
currentDevOpts = ¤t_devices->at(i);
|
||||||
|
|
||||||
|
currentDevOpts->mode = argument;
|
||||||
|
currentDevOpts->hasOption = true;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return found;
|
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)
|
if(argument.size() == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -694,16 +725,30 @@ bool OptionBrightness(std::vector<DeviceOptions>* current_devices, std::string a
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = false;
|
/*---------------------------------------------------------*\
|
||||||
|
| If a device is not selected i.e. size() == 0 |
|
||||||
|
| then add brightness to allDeviceOptions |
|
||||||
|
\*---------------------------------------------------------*/
|
||||||
|
bool found = false;
|
||||||
|
DeviceOptions* currentDevOpts = &options->allDeviceOptions;
|
||||||
|
|
||||||
for(size_t i = 0; i < current_devices->size(); i++)
|
if(current_devices->size() == 0)
|
||||||
{
|
{
|
||||||
DeviceOptions* currentDevOpts = ¤t_devices->at(i);
|
currentDevOpts->brightness = std::min(std::max(std::stoi(argument), 0),(int)brightness_percentage);
|
||||||
|
currentDevOpts->hasOption = true;
|
||||||
currentDevOpts->brightness = std::min(std::max(std::stoi(argument), 0),(int)brightness_percentage);
|
|
||||||
currentDevOpts->hasOption = true;
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < current_devices->size(); i++)
|
||||||
|
{
|
||||||
|
DeviceOptions* currentDevOpts = ¤t_devices->at(i);
|
||||||
|
|
||||||
|
currentDevOpts->brightness = std::min(std::max(std::stoi(argument), 0),(int)brightness_percentage);
|
||||||
|
currentDevOpts->hasOption = true;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue