1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 11:59:58 +03:00

Add optional search string support for CLI "help" command (#9250)

Add optional search string support for CLI "help" command
This commit is contained in:
Michael Keller 2019-12-02 11:30:48 +13:00 committed by GitHub
commit 00855c4bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6315,7 +6315,7 @@ const clicmd_t cmdTable[] = {
#if defined(USE_GYRO_REGISTER_DUMP) && !defined(SIMULATOR_BUILD) #if defined(USE_GYRO_REGISTER_DUMP) && !defined(SIMULATOR_BUILD)
CLI_COMMAND_DEF("gyroregisters", "dump gyro config registers contents", NULL, cliDumpGyroRegisters), CLI_COMMAND_DEF("gyroregisters", "dump gyro config registers contents", NULL, cliDumpGyroRegisters),
#endif #endif
CLI_COMMAND_DEF("help", NULL, NULL, cliHelp), CLI_COMMAND_DEF("help", "display command help", "[search string]", cliHelp),
#ifdef USE_LED_STRIP_STATUS_MODE #ifdef USE_LED_STRIP_STATUS_MODE
CLI_COMMAND_DEF("led", "configure leds", NULL, cliLed), CLI_COMMAND_DEF("led", "configure leds", NULL, cliLed),
#endif #endif
@ -6400,9 +6400,24 @@ const clicmd_t cmdTable[] = {
static void cliHelp(char *cmdline) static void cliHelp(char *cmdline)
{ {
UNUSED(cmdline); bool anyMatches = false;
for (uint32_t i = 0; i < ARRAYLEN(cmdTable); i++) { for (uint32_t i = 0; i < ARRAYLEN(cmdTable); i++) {
bool printEntry = false;
if (isEmpty(cmdline)) {
printEntry = true;
} else {
if (strcasestr(cmdTable[i].name, cmdline)
#ifndef MINIMAL_CLI
|| strcasestr(cmdTable[i].description, cmdline)
#endif
) {
printEntry = true;
}
}
if (printEntry) {
anyMatches = true;
cliPrint(cmdTable[i].name); cliPrint(cmdTable[i].name);
#ifndef MINIMAL_CLI #ifndef MINIMAL_CLI
if (cmdTable[i].description) { if (cmdTable[i].description) {
@ -6414,6 +6429,10 @@ static void cliHelp(char *cmdline)
#endif #endif
cliPrintLinefeed(); cliPrintLinefeed();
} }
}
if (!isEmpty(cmdline) && !anyMatches) {
cliPrintErrorLinef("NO MATCHES FOR '%s'", cmdline);
}
} }
static void processCharacter(const char c) static void processCharacter(const char c)