shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
diff --git a/drivers/pci/pci_shell.c b/drivers/pci/pci_shell.c
index b1ae3ce..3cf03ca 100644
--- a/drivers/pci/pci_shell.c
+++ b/drivers/pci/pci_shell.c
@@ -44,11 +44,6 @@
.bar = PCI_BAR_ANY,
};
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 1;
- }
-
pci_bus_scan_init();
while (pci_bus_scan(&info)) {
diff --git a/include/shell/shell.h b/include/shell/shell.h
index b886b5d..e09caf5 100644
--- a/include/shell/shell.h
+++ b/include/shell/shell.h
@@ -342,7 +342,6 @@
*/
struct shell_flags {
u32_t insert_mode :1; /*!< Controls insert mode for text introduction.*/
- u32_t show_help :1; /*!< Shows help if -h or --help option present.*/
u32_t use_colors :1; /*!< Controls colored syntax.*/
u32_t echo :1; /*!< Controls shell echo.*/
u32_t processing :1; /*!< Shell is executing process function.*/
@@ -616,18 +615,6 @@
void shell_process(const struct shell *shell);
/**
- * @brief Informs that a command has been called with -h or --help option.
- *
- * @param[in] shell Pointer to the shell instance.
- *
- * @return True if help has been requested.
- */
-static inline bool shell_help_requested(const struct shell *shell)
-{
- return shell->ctx->internal.flags.show_help;
-}
-
-/**
* @brief Prints the current command help.
*
* Function will print a help string with the currently entered command and
diff --git a/samples/mpu/mpu_test/src/main.c b/samples/mpu/mpu_test/src/main.c
index 0727d81..c3c4727 100644
--- a/samples/mpu/mpu_test/src/main.c
+++ b/samples/mpu/mpu_test/src/main.c
@@ -34,11 +34,6 @@
u32_t *p_mem = (u32_t *) RESERVED_MEM_MAP;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
/* Reads from an address that is reserved in the memory map */
PR_SHELL(shell, "The value is: %d\n", *p_mem);
@@ -55,11 +50,6 @@
u32_t value[2];
u32_t offset;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
flash_dev = device_get_binding(DT_FLASH_DEV_NAME);
/* 128K reserved to the application */
@@ -90,11 +80,6 @@
struct device *flash_dev;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
flash_dev = device_get_binding(DT_FLASH_DEV_NAME);
/* 16K reserved to the application */
@@ -123,11 +108,6 @@
/* 16K reserved to the application */
u32_t *p_mem = (u32_t *) (FLASH_MEM + 0x4000);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
PR_SHELL(shell, "write address: 0x%x\n", FLASH_MEM + 0x4000);
/* Write in to boot FLASH/ROM */
@@ -144,11 +124,6 @@
void (*func_ptr)(void) = (void (*)(void)) RAM_MEM;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
/* Run code located in RAM */
func_ptr();
diff --git a/samples/net/promiscuous_mode/src/main.c b/samples/net/promiscuous_mode/src/main.c
index 79f8461..d608be1 100644
--- a/samples/net/promiscuous_mode/src/main.c
+++ b/samples/net/promiscuous_mode/src/main.c
@@ -146,11 +146,6 @@
char *endptr;
int idx, ret;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (argc < 2) {
shell_fprintf(shell, SHELL_ERROR, "Invalid arguments.\n");
return -ENOEXEC;
diff --git a/samples/net/rpl_border_router/src/shell.c b/samples/net/rpl_border_router/src/shell.c
index 9b283b3..4b2c179 100644
--- a/samples/net/rpl_border_router/src/shell.c
+++ b/samples/net/rpl_border_router/src/shell.c
@@ -24,11 +24,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
shell_fprintf(shell, SHELL_INFO, "Starting global repair...\n");
net_rpl_repair_root(CONFIG_NET_RPL_DEFAULT_INSTANCE);
@@ -43,11 +38,6 @@
enum coap_request_type type;
int r;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (argc != 3 || !argv[1] || !argv[2]) {
shell_fprintf(shell, SHELL_ERROR, "Invalid arguments.\n");
return -ENOEXEC;
diff --git a/samples/net/zperf/src/zperf_shell.c b/samples/net/zperf/src/zperf_shell.c
index 78378a9..8c7477c 100644
--- a/samples/net/zperf/src/zperf_shell.c
+++ b/samples/net/zperf/src/zperf_shell.c
@@ -225,7 +225,7 @@
do_init(shell);
if (IS_ENABLED(CONFIG_NET_IPV6) && !IS_ENABLED(CONFIG_NET_IPV4)) {
- if (argc != 3 || shell_help_requested(shell)) {
+ if (argc != 3) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -243,7 +243,7 @@
}
if (IS_ENABLED(CONFIG_NET_IPV4) && !IS_ENABLED(CONFIG_NET_IPV6)) {
- if (argc != 2 || shell_help_requested(shell)) {
+ if (argc != 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -261,7 +261,7 @@
if (IS_ENABLED(CONFIG_NET_IPV6) && IS_ENABLED(CONFIG_NET_IPV4)) {
if (net_addr_pton(AF_INET6, argv[start + 1], &ipv6) < 0) {
- if (argc != 2 || shell_help_requested(shell)) {
+ if (argc != 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -277,7 +277,7 @@
"Setting IP address %s\n",
net_sprint_ipv4_addr(&ipv4));
} else {
- if (argc != 3 || shell_help_requested(shell)) {
+ if (argc != 3) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -307,11 +307,6 @@
do_init(shell);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (argc >= 2) {
port = strtoul(argv[start + 1], NULL, 10);
} else {
@@ -983,11 +978,6 @@
do_init(shell);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (argc >= 2) {
port = strtoul(argv[1], NULL, 10);
} else {
diff --git a/samples/subsys/shell/shell_module/src/dynamic_cmd.c b/samples/subsys/shell/shell_module/src/dynamic_cmd.c
index e61af2e..b560c84 100644
--- a/samples/subsys/shell/shell_module/src/dynamic_cmd.c
+++ b/samples/subsys/shell/shell_module/src/dynamic_cmd.c
@@ -21,7 +21,7 @@
static int cmd_dynamic(const struct shell *shell, size_t argc, char **argv)
{
- if ((argc == 1) || shell_help_requested(shell)) {
+ if ((argc == 1)) {
shell_help_print(shell);
return 0;
}
@@ -49,11 +49,6 @@
u8_t idx;
u16_t cmd_len;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
if (argc != 2) {
shell_fprintf(shell, SHELL_ERROR,
"%s: bad parameter count\r\n", argv[0]);
@@ -102,11 +97,6 @@
static int cmd_dynamic_show(const struct shell *shell,
size_t argc, char **argv)
{
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
if (argc != 1) {
shell_fprintf(shell, SHELL_ERROR,
"%s: bad parameter count\r\n", argv[0]);
@@ -132,11 +122,6 @@
static int cmd_dynamic_execute(const struct shell *shell,
size_t argc, char **argv)
{
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 0;
- }
-
if (argc != 2) {
shell_fprintf(shell, SHELL_ERROR,
"%s: bad parameter count\r\n", argv[0]);
@@ -160,7 +145,7 @@
static int cmd_dynamic_remove(const struct shell *shell, size_t argc,
char **argv)
{
- if ((argc == 1) || shell_help_requested(shell)) {
+ if (argc == 1) {
shell_help_print(shell);
return 0;
}
diff --git a/subsys/logging/log_cmds.c b/subsys/logging/log_cmds.c
index ad3a575..5f7fc7b 100644
--- a/subsys/logging/log_cmds.c
+++ b/subsys/logging/log_cmds.c
@@ -441,7 +441,7 @@
static int cmd_log(const struct shell *shell, size_t argc, char **argv)
{
- if ((argc == 1) || shell_help_requested(shell)) {
+ if (argc == 1) {
shell_help_print(shell);
return 0;
}
diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c
index 3fa153c..2510212 100644
--- a/subsys/net/ip/net_shell.c
+++ b/subsys/net/ip/net_shell.c
@@ -1152,11 +1152,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
user_data.shell = shell;
@@ -1380,11 +1375,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if CONFIG_NET_APP_LOG_LEVEL >= LOG_LEVEL_DBG
if (IS_ENABLED(CONFIG_NET_APP_SERVER)) {
user_data.shell = shell;
@@ -1458,11 +1448,6 @@
ARG_UNUSED(argc);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_ARP)
if (!argv[arg]) {
/* ARP cache content */
@@ -1488,11 +1473,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_ARP)
PR("Flushing ARP cache.\n");
net_arp_clear_cache(NULL);
@@ -1511,11 +1491,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
PR(" Context \tIface Flags Local \tRemote\n");
user_data.shell = shell;
@@ -1693,11 +1668,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_DNS_RESOLVER)
ctx = dns_resolve_get_default();
if (!ctx) {
@@ -1731,10 +1701,6 @@
static int cmd_net_dns_query(const struct shell *shell, size_t argc,
char *argv[])
{
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
#if defined(CONFIG_DNS_RESOLVER)
#define DNS_TIMEOUT K_MSEC(2000) /* ms */
@@ -1792,11 +1758,6 @@
struct dns_resolve_context *ctx;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_DNS_RESOLVER)
if (argv[1]) {
/* So this is a query then */
@@ -2338,11 +2299,6 @@
int port;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_GPTP)
if (!argv[arg]) {
PR_WARNING("Port number must be given.\n");
@@ -2375,11 +2331,6 @@
int arg = 1;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_GPTP)
if (argv[arg]) {
cmd_net_gptp_port(shell, argc, argv);
@@ -2497,11 +2448,6 @@
static int cmd_net_http_monitor(const struct shell *shell, size_t argc,
char *argv[])
{
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_DEBUG_HTTP_CONN) && defined(CONFIG_HTTP_SERVER)
PR_INFO("Activating HTTP monitor. Type \"net http\" "
"to disable HTTP connection monitoring.\n");
@@ -2524,11 +2470,6 @@
int arg = 2;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_DEBUG_HTTP_CONN) && defined(CONFIG_HTTP_SERVER)
http_monitor_count = 0;
@@ -2580,11 +2521,6 @@
struct net_if *iface;
int idx, ret;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
idx = get_iface_idx(shell, argv[1]);
if (idx < 0) {
return -ENOEXEC;
@@ -2618,11 +2554,6 @@
struct net_if *iface;
int idx, ret;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
idx = get_iface_idx(shell, argv[1]);
if (idx < 0) {
return -ENOEXEC;
@@ -2721,10 +2652,6 @@
#if defined(CONFIG_NET_IPV6)
struct net_shell_user_data user_data;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
PR("IPv6 support : %s\n",
IS_ENABLED(CONFIG_NET_IPV6) ?
@@ -2792,11 +2719,6 @@
struct net_shell_user_data user_data;
int idx;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (argv[1]) {
idx = get_iface_idx(shell, argv[1]);
if (idx < 0) {
@@ -2912,11 +2834,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
net_pkt_get_info(&rx, &tx, &rx_data, &tx_data);
PR("Fragment length %d bytes\n", CONFIG_NET_BUF_DATA_SIZE);
@@ -2976,11 +2893,6 @@
int ret;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_IPV6)
if (!argv[1]) {
PR_WARNING("Neighbor IPv6 address missing.\n");
@@ -3082,11 +2994,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_IPV6)
user_data.shell = shell;
user_data.user_data = &count;
@@ -3247,11 +3154,6 @@
ARG_UNUSED(argc);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
host = argv[1];
if (!host) {
@@ -3306,11 +3208,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_ROUTE) || defined(CONFIG_NET_ROUTE_MCAST)
user_data.shell = shell;
#endif
@@ -3390,11 +3287,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_RPL)
mode = net_rpl_get_mode();
PR("RPL Configuration\n");
@@ -3551,11 +3443,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
for (info = __net_stack_start; info != __net_stack_end; info++) {
net_analyze_stack_get_values(K_THREAD_STACK_BUFFER(info->stack),
info->size, &pcnt, &unused);
@@ -3631,11 +3518,6 @@
struct net_shell_user_data user_data;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_STATISTICS)
user_data.shell = shell;
@@ -3664,11 +3546,6 @@
#endif
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_STATISTICS)
#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
idx = strtol(argv[1], &endptr, 10);
@@ -3703,11 +3580,6 @@
static int cmd_net_stats(const struct shell *shell, size_t argc, char *argv[])
{
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_STATISTICS)
if (!argv[1]) {
cmd_net_stats_all(shell, argc, argv);
@@ -3940,11 +3812,6 @@
u16_t port;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_TCP)
/* tcp connect <ip> port */
if (tcp_ctx && net_context_is_used(tcp_ctx)) {
@@ -3988,11 +3855,6 @@
struct net_pkt *pkt;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_TCP)
/* tcp send <data> */
if (!tcp_ctx || !net_context_is_used(tcp_ctx)) {
@@ -4043,11 +3905,6 @@
int ret;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_TCP)
/* tcp close */
if (!tcp_ctx || !net_context_is_used(tcp_ctx)) {
@@ -4075,11 +3932,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
return 0;
}
@@ -4152,11 +4004,6 @@
int count;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_VLAN)
count = 0;
@@ -4183,11 +4030,6 @@
u32_t iface_idx;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_VLAN)
/* vlan add <tag> <interface index> */
if (!argv[++arg]) {
@@ -4260,11 +4102,6 @@
u16_t tag;
#endif
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
#if defined(CONFIG_NET_VLAN)
/* vlan del <tag> */
if (!argv[++arg]) {
diff --git a/subsys/net/l2/bluetooth/bluetooth_shell.c b/subsys/net/l2/bluetooth/bluetooth_shell.c
index bee2f9e..b0a1751 100644
--- a/subsys/net/l2/bluetooth/bluetooth_shell.c
+++ b/subsys/net/l2/bluetooth/bluetooth_shell.c
@@ -84,7 +84,7 @@
bt_addr_le_t addr;
struct net_if *iface = net_if_get_default();
- if (argc < 3 || shell_help_requested(shell)) {
+ if (argc < 3) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -112,7 +112,7 @@
{
struct net_if *iface = net_if_get_default();
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -133,11 +133,6 @@
{
struct net_if *iface = net_if_get_default();
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (net_mgmt(NET_REQUEST_BT_DISCONNECT, iface, NULL, 0)) {
shell_fprintf(shell, SHELL_WARNING,
"Disconnect failed\n");
@@ -154,7 +149,7 @@
{
struct net_if *iface = net_if_get_default();
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
diff --git a/subsys/net/l2/ieee802154/ieee802154_shell.c b/subsys/net/l2/ieee802154/ieee802154_shell.c
index eae3784..cb7f227 100644
--- a/subsys/net/l2/ieee802154/ieee802154_shell.c
+++ b/subsys/net/l2/ieee802154/ieee802154_shell.c
@@ -36,11 +36,6 @@
ARG_UNUSED(argc);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
@@ -77,7 +72,7 @@
struct net_if *iface = net_if_get_ieee802154();
char ext_addr[MAX_EXT_ADDR_STR_LEN];
- if (argc < 3 || shell_help_requested(shell)) {
+ if (argc < 3) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -123,11 +118,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
@@ -217,7 +207,7 @@
u32_t scan_type;
int ret;
- if (argc < 3 || shell_help_requested(shell)) {
+ if (argc < 3) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -288,7 +278,7 @@
struct net_if *iface = net_if_get_ieee802154();
u16_t channel;
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -324,11 +314,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
@@ -357,7 +342,7 @@
ARG_UNUSED(argc);
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -393,11 +378,6 @@
ARG_UNUSED(argc);
ARG_UNUSED(argv);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
@@ -424,7 +404,7 @@
struct net_if *iface = net_if_get_ieee802154();
u8_t addr[IEEE802154_EXT_ADDR_LENGTH];
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -463,11 +443,6 @@
struct net_if *iface = net_if_get_ieee802154();
u8_t addr[IEEE802154_EXT_ADDR_LENGTH];
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
@@ -504,7 +479,7 @@
struct net_if *iface = net_if_get_ieee802154();
u16_t short_addr;
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -537,11 +512,6 @@
struct net_if *iface = net_if_get_ieee802154();
u16_t short_addr;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
@@ -568,7 +538,7 @@
struct net_if *iface = net_if_get_ieee802154();
s16_t tx_power;
- if (argc < 2 || shell_help_requested(shell)) {
+ if (argc < 2) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -601,11 +571,6 @@
struct net_if *iface = net_if_get_ieee802154();
s16_t tx_power;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (!iface) {
shell_fprintf(shell, SHELL_INFO,
"No IEEE 802.15.4 interface found.\n");
diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c
index e97a48d..2ca1dd5 100644
--- a/subsys/net/l2/wifi/wifi_shell.c
+++ b/subsys/net/l2/wifi/wifi_shell.c
@@ -151,7 +151,7 @@
char *endptr;
int idx = 3;
- if (shell_help_requested(shell) || argc < 3) {
+ if (argc < 3) {
shell_help_print(shell);
return -ENOEXEC;
}
@@ -212,11 +212,6 @@
struct net_if *iface = net_if_get_default();
int status;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
context.disconnecting = true;
context.shell = shell;
@@ -245,11 +240,6 @@
{
struct net_if *iface = net_if_get_default();
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0)) {
shell_fprintf(shell, SHELL_WARNING, "Scan request failed\n");
diff --git a/subsys/net/lib/openthread/platform/shell.c b/subsys/net/lib/openthread/platform/shell.c
index ac6cee0..353f5ec 100644
--- a/subsys/net/lib/openthread/platform/shell.c
+++ b/subsys/net/lib/openthread/platform/shell.c
@@ -35,11 +35,6 @@
size_t arg_len = 0;
int i;
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return -ENOEXEC;
- }
-
if (argc < 2) {
return -ENOEXEC;
}
diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c
index b3449b8..64ce48e 100644
--- a/subsys/shell/shell.c
+++ b/subsys/shell/shell.c
@@ -62,15 +62,6 @@
shell_fprintf_buffer_flush(shell->fprintf_ctx);
}
-static inline void help_flag_set(const struct shell *shell)
-{
- shell->ctx->internal.flags.show_help = 1;
-}
-static inline void help_flag_clear(const struct shell *shell)
-{
- shell->ctx->internal.flags.show_help = 0;
-}
-
/* Function returns true if delete escape code shall be interpreted as
* backspace.
*/
@@ -974,12 +965,16 @@
return NULL;
}
-static int exec_cmd(const struct shell *shell, size_t argc, char **argv)
+static int exec_cmd(const struct shell *shell, size_t argc, char **argv,
+ struct shell_static_entry help_entry)
{
int ret_val = 0;
if (shell->ctx->active_cmd.handler == NULL) {
- if (shell->ctx->active_cmd.help) {
+ if (help_entry.help) {
+ if (help_entry.help != shell->ctx->active_cmd.help) {
+ shell->ctx->active_cmd = help_entry;
+ }
shell_help_print(shell);
} else {
shell_fprintf(shell, SHELL_ERROR,
@@ -1014,12 +1009,9 @@
}
clear:
- help_flag_clear(shell);
-
return ret_val;
}
-
/* Function is analyzing the command buffer to find matching commands. Next, it
* invokes the last recognized command which has a handler and passes the rest
* of command buffer as arguments.
@@ -1030,6 +1022,7 @@
char *argv[CONFIG_SHELL_ARGC_MAX + 1]; /* +1 reserved for NULL */
const struct shell_static_entry *p_static_entry = NULL;
const struct shell_cmd_entry *p_cmd = NULL;
+ struct shell_static_entry help_entry;
size_t cmd_lvl = SHELL_CMD_ROOT_LVL;
size_t cmd_with_handler_lvl = 0;
bool wildcard_found = false;
@@ -1080,6 +1073,7 @@
/* checking if root command has a handler */
shell->ctx->active_cmd = *p_cmd->u.entry;
+ help_entry = *p_cmd->u.entry;
p_cmd = p_cmd->u.entry->subcmd;
cmd_lvl++;
@@ -1096,8 +1090,15 @@
/* Command called with help option so it makes no sense
* to search deeper commands.
*/
- help_flag_set(shell);
- break;
+ if (help_entry.help) {
+ shell->ctx->active_cmd = help_entry;
+ shell_help_print(shell);
+ return 1;
+ }
+
+ shell_fprintf(shell, SHELL_ERROR,
+ SHELL_MSG_SPECIFY_SUBCOMMAND);
+ return -ENOEXEC;
}
if (IS_ENABLED(CONFIG_SHELL_WILDCARD)) {
@@ -1147,7 +1148,6 @@
"Error: requested"
" multiple function"
" executions\r\n");
- help_flag_clear(shell);
return -ENOEXEC;
}
@@ -1156,6 +1156,10 @@
shell->ctx->active_cmd = *p_static_entry;
cmd_with_handler_lvl = cmd_lvl;
}
+ /* checking if function has a help handler */
+ if (p_static_entry->help != NULL) {
+ help_entry = *p_static_entry;
+ }
cmd_lvl++;
cmd_idx = 0;
@@ -1176,7 +1180,7 @@
/* Executing the deepest found handler. */
return exec_cmd(shell, argc - cmd_with_handler_lvl,
- &argv[cmd_with_handler_lvl]);
+ &argv[cmd_with_handler_lvl], help_entry);
}
static void shell_transport_evt_handler(enum shell_transport_evt evt_type,
@@ -1740,11 +1744,6 @@
int shell_cmd_precheck(const struct shell *shell,
bool arg_cnt_ok)
{
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 1; /* help printed */
- }
-
if (!arg_cnt_ok) {
shell_fprintf(shell, SHELL_ERROR,
"%s: wrong parameter count\n",
diff --git a/subsys/shell/shell_cmds.c b/subsys/shell/shell_cmds.c
index e77558d..99cc565 100644
--- a/subsys/shell/shell_cmds.c
+++ b/subsys/shell/shell_cmds.c
@@ -434,10 +434,7 @@
{
ARG_UNUSED(argc);
- if (shell_help_requested(shell)) {
- shell_help_print(shell);
- return 1;
- } else if (argc == 1) {
+ if (argc == 1) {
shell_help_print(shell);
} else {
shell_fprintf(shell, SHELL_ERROR, "%s:%s%s\n", argv[0],