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
67
cli.cpp
67
cli.cpp
|
|
@ -641,18 +641,12 @@ 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 = ¤t_devices->at(i);
|
||||
|
||||
if(ParseColors(argument, currentDevOpts))
|
||||
{
|
||||
currentDevOpts->hasOption = true;
|
||||
found = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -661,10 +655,33 @@ bool OptionColor(std::vector<DeviceOptions>* current_devices, std::string argume
|
|||
}
|
||||
}
|
||||
|
||||
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 = ¤t_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 = ¤t_devices->at(i);
|
||||
currentDevOpts = ¤t_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 = ¤t_devices->at(i);
|
||||
|
|
@ -704,6 +748,7 @@ bool OptionBrightness(std::vector<DeviceOptions>* current_devices, std::string a
|
|||
currentDevOpts->hasOption = true;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue