Add Network Tools And Nested Command Completion

This commit is contained in:
2026-08-23 15:47:28 +02:00
parent c5f3595173
commit f9d3e9ece5
12 changed files with 1141 additions and 94 deletions
+138
View File
@@ -0,0 +1,138 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* Full-line linenoise completion for nested project console commands. */
#include "console_completion.h"
#include <stddef.h>
#include <string.h>
#include "esp_console.h"
#include "linenoise/linenoise.h"
/* Keep full-line candidate strings grouped by their registered root command. */
static const char *const s_completion_candidates[] = {
/* Hardware debug commands and safe fixed arguments. */
"debug transceiver",
"debug transceiver enable",
"debug transceiver disable",
"debug drivers",
"debug loopback-a",
"debug loopback-b",
"debug valid-test",
"debug uart-loopback",
"debug uart-suite",
"debug cts-flow-test",
"debug rts-flow-test",
/* Serial service lifecycle, persistence, counters, and settings. */
"serial status",
"serial start",
"serial stop",
"serial set",
"serial set baud",
"serial set data-bits",
"serial set data-bits 7",
"serial set data-bits 8",
"serial set parity",
"serial set parity none",
"serial set parity even",
"serial set parity odd",
"serial set stop-bits",
"serial set stop-bits 1",
"serial set stop-bits 2",
"serial set flow",
"serial set flow none",
"serial set flow rts-cts",
"serial set dtr",
"serial set dtr inactive",
"serial set dtr active",
"serial set dtr on-connect",
"serial set rts-threshold",
"serial save",
"serial load",
"serial defaults",
"serial reset",
"serial counters",
"serial clear-counters",
/* Session broker inspection, ownership, and data operations. */
"broker status",
"broker clients",
"broker counters",
"broker clear-counters",
"broker connect",
"broker disconnect",
"broker request-writer",
"broker release-writer",
"broker force-writer",
"broker send-hex",
"broker read",
"broker events",
/* Native USB CDC status and writer ownership. */
"usb help",
"usb status",
"usb counters",
"usb clear-counters",
"usb request-writer",
"usb release-writer",
/* Wi-Fi lifecycle, persistence, profiles, AP policy, and diagnostics. */
"wifi status",
"wifi profiles",
"wifi counters",
"wifi clear-counters",
"wifi start",
"wifi stop",
"wifi reconnect",
"wifi save",
"wifi load",
"wifi defaults",
"wifi reset",
"wifi profile",
"wifi profile set",
"wifi profile secret",
"wifi profile enable",
"wifi profile disable",
"wifi profile delete",
"wifi ap",
"wifi ap policy",
"wifi ap policy off",
"wifi ap policy fallback",
"wifi ap policy always",
"wifi ap ssid",
"wifi ap channel",
"wifi ap secret",
"wifi ap show-secret",
"wifi ping",
"wifi nslookup",
"wifi traceroute",
};
static void console_completion_callback(const char *buffer, linenoiseCompletions *completions)
{
/* Preserve ESP-IDF completion for registered root command names. */
if (strchr(buffer, ' ') == NULL) {
esp_console_get_completion(buffer, completions);
return;
}
const size_t buffer_length = strlen(buffer);
for (size_t index = 0;
index < sizeof(s_completion_candidates) / sizeof(s_completion_candidates[0]);
++index) {
const char *const candidate = s_completion_candidates[index];
const size_t candidate_length = strlen(candidate);
/* linenoise expects the complete replacement line, not only its suffix. */
if (candidate_length > buffer_length &&
strncmp(candidate, buffer, buffer_length) == 0) {
linenoiseAddCompletion(completions, candidate);
}
}
}
void console_completion_install(void)
{
linenoiseSetCompletionCallback(&console_completion_callback);
}