mirror of
https://github.com/MaJerle/lwshell.git
synced 2025-01-25 13:02:54 +08:00
Add option for "listcmd" to list all registered commands
This commit is contained in:
parent
6f475afcae
commit
270c926c3b
@ -38,6 +38,7 @@
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#define LWSHELL_CFG_USE_OUTPUT 1
|
||||
#define LWSHELL_CFG_USE_OUTPUT 1
|
||||
#define LWSHELL_CFG_USE_ENABLE_LIST_CMD 1
|
||||
|
||||
#endif /* LWSHELL_HDR_OPTS_H */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* \file lwshell_opt.h
|
||||
* \brief LwSHELL options
|
||||
*/
|
||||
@ -97,6 +97,15 @@ extern "C" {
|
||||
#define LWSHELL_CFG_USE_OUTPUT 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Enables `1` or disables `0` generic ˙listcmd` command to list of registered commands
|
||||
*
|
||||
* \ref LWSHELL_CFG_USE_OUTPUT must be enabled to use this feature
|
||||
*/
|
||||
#ifndef LWSHELL_CFG_USE_ENABLE_LIST_CMD
|
||||
#define LWSHELL_CFG_USE_ENABLE_LIST_CMD 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \}
|
||||
*/
|
||||
|
@ -34,6 +34,11 @@
|
||||
#include <string.h>
|
||||
#include "lwshell/lwshell.h"
|
||||
|
||||
/* Check enabled features */
|
||||
#if LWSHELL_CFG_USE_ENABLE_LIST_CMD && !LWSHELL_CFG_USE_OUTPUT
|
||||
#error "To use list command feature, LWSHELL_CFG_USE_OUTPUT must be enabled"
|
||||
#endif
|
||||
|
||||
/* Default characters */
|
||||
#define LWSHELL_ASCII_NULL 0x00/*!< Null character */
|
||||
#define LWSHELL_ASCII_BACKSPACE 0x08/*!< Backspace */
|
||||
@ -176,6 +181,18 @@ prv_parse_input(lwshell_t* lw) {
|
||||
} else {
|
||||
c->fn(lw->argc, lw->argv);
|
||||
}
|
||||
#if LWSHELL_CFG_USE_ENABLE_LIST_CMD
|
||||
} else if (strncmp(lw->argv[0], "listcmd", 7) == 0) {
|
||||
LW_OUTPUT(lw, "List of registered commands\r\n");
|
||||
for (size_t i = 0; i < cmds_cnt; ++i) {
|
||||
LW_OUTPUT(lw, cmds[i].name);
|
||||
LW_OUTPUT(lw, "\t\t\t");
|
||||
LW_OUTPUT(lw, cmds[i].desc);
|
||||
LW_OUTPUT(lw, "\r\n");
|
||||
}
|
||||
#endif /* LWSHELL_CFG_USE_ENABLE_LIST_CMD */
|
||||
} else {
|
||||
LW_OUTPUT(lw, "Unknown command\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user