From a0e090489b1f4e75055eed061bc72d3f677e6850 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Wed, 8 Dec 2021 17:38:04 +0300 Subject: [PATCH] terminal: get rid of ctx.argc No need to duplicate argv::size() --- code/espurna/ifan.cpp | 2 +- code/espurna/influxdb.cpp | 2 +- code/espurna/led.cpp | 4 ++-- code/espurna/light.cpp | 14 +++++++------- code/espurna/mqtt.cpp | 2 +- code/espurna/ntp.cpp | 2 +- code/espurna/ota_asynctcp.cpp | 2 +- code/espurna/ota_httpupdate.cpp | 2 +- code/espurna/relay.cpp | 4 ++-- code/espurna/rfbridge.cpp | 10 +++++----- code/espurna/rpnrules.cpp | 2 +- code/espurna/sensors/PZEM004TSensor.h | 4 ++-- code/espurna/sensors/PZEM004TV30Sensor.h | 2 +- code/espurna/settings.cpp | 6 +++--- code/espurna/storage_eeprom.cpp | 2 +- code/espurna/telnet.cpp | 2 +- code/espurna/terminal.cpp | 12 ++++++------ code/espurna/terminal_commands.cpp | 4 ++-- code/espurna/terminal_commands.h | 1 - code/espurna/terminal_parsing.cpp | 3 +-- code/espurna/terminal_parsing.h | 8 +++----- code/test/unit/terminal/terminal.cpp | 16 ++++++++-------- 22 files changed, 51 insertions(+), 55 deletions(-) diff --git a/code/espurna/ifan.cpp b/code/espurna/ifan.cpp index 02e21033..f6eb6ea2 100644 --- a/code/espurna/ifan.cpp +++ b/code/espurna/ifan.cpp @@ -347,7 +347,7 @@ void setup() { #if TERMINAL_SUPPORT terminalRegisterCommand(F("SPEED"), [](const terminal::CommandContext& ctx) { - if (ctx.argc == 2) { + if (ctx.argv.size() == 2) { updateSpeedFromPayload(ctx.argv[1]); } diff --git a/code/espurna/influxdb.cpp b/code/espurna/influxdb.cpp index df1090f5..0f4749fd 100644 --- a/code/espurna/influxdb.cpp +++ b/code/espurna/influxdb.cpp @@ -306,7 +306,7 @@ void idbSetup() { #if TERMINAL_SUPPORT terminalRegisterCommand(F("IDB.SEND"), [](const terminal::CommandContext& ctx) { - if (ctx.argc != 4) { + if (ctx.argv.size() != 4) { terminalError(F("idb.send ")); return; } diff --git a/code/espurna/led.cpp b/code/espurna/led.cpp index 15e9f6f2..98124613 100644 --- a/code/espurna/led.cpp +++ b/code/espurna/led.cpp @@ -1030,7 +1030,7 @@ namespace terminal { void setup() { terminalRegisterCommand(F("LED"), [](const ::terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { size_t id; if (!tryParseId(ctx.argv[1].c_str(), ledCount, id)) { terminalError(ctx, F("Invalid ledID")); @@ -1038,7 +1038,7 @@ void setup() { } auto& led = internal::leds[id]; - if (ctx.argc > 2) { + if (ctx.argv.size() > 2) { led.mode(LedMode::Manual); pattern(led, Pattern(ctx.argv[2])); } else { diff --git a/code/espurna/light.cpp b/code/espurna/light.cpp index cbbd687f..a53bb837 100644 --- a/code/espurna/light.cpp +++ b/code/espurna/light.cpp @@ -2379,7 +2379,7 @@ namespace { void _lightInitCommands() { terminalRegisterCommand(F("LIGHT"), [](const terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { if (!_lightParsePayload(ctx.argv[1].c_str())) { terminalError(ctx, F("Invalid payload")); return; @@ -2392,7 +2392,7 @@ void _lightInitCommands() { }); terminalRegisterCommand(F("BRIGHTNESS"), [](const terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { _lightAdjustBrightness(ctx.argv[1]); lightUpdate(); } @@ -2416,7 +2416,7 @@ void _lightInitCommands() { String(_light_channels[channel].current, 2).c_str()); }; - if (ctx.argc > 2) { + if (ctx.argv.size() > 2) { size_t id; if (!_lightTryParseChannel(ctx.argv[1].c_str(), id)) { terminalError(ctx, F("Invalid channel ID")); @@ -2436,7 +2436,7 @@ void _lightInitCommands() { }); terminalRegisterCommand(F("RGB"), [](const terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { _lightFromRgbPayload(ctx.argv[1].c_str()); lightUpdate(); } @@ -2445,7 +2445,7 @@ void _lightInitCommands() { }); terminalRegisterCommand(F("HSV"), [](const terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { _lightFromHsvPayload(ctx.argv[1].c_str()); lightUpdate(); } @@ -2454,7 +2454,7 @@ void _lightInitCommands() { }); terminalRegisterCommand(F("KELVIN"), [](const terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { _lightAdjustKelvin(ctx.argv[1]); lightUpdate(); } @@ -2463,7 +2463,7 @@ void _lightInitCommands() { }); terminalRegisterCommand(F("MIRED"), [](const terminal::CommandContext& ctx) { - if (ctx.argc > 1) { + if (ctx.argv.size() > 1) { _lightAdjustMireds(ctx.argv[1]); lightUpdate(); } diff --git a/code/espurna/mqtt.cpp b/code/espurna/mqtt.cpp index 2521f1ae..bb48417e 100644 --- a/code/espurna/mqtt.cpp +++ b/code/espurna/mqtt.cpp @@ -800,7 +800,7 @@ void _mqttInitCommands() { }); terminalRegisterCommand(F("MQTT.SEND"), [](const terminal::CommandContext& ctx) { - if (ctx.argc == 3) { + if (ctx.argv.size() == 3) { if (mqttSend(ctx.argv[1].c_str(), ctx.argv[2].c_str(), false, false)) { terminalOK(ctx); } else { diff --git a/code/espurna/ntp.cpp b/code/espurna/ntp.cpp index 3ee29d48..23025772 100644 --- a/code/espurna/ntp.cpp +++ b/code/espurna/ntp.cpp @@ -647,7 +647,7 @@ void ntpSetup() { }); #else terminalRegisterCommand(F("NTP.SETTIME"), [](const terminal::CommandContext& ctx) { - if (ctx.argc != 2) { + if (ctx.argv.size() != 2) { terminalError(ctx, F("NTP.SETTIME