From e0be6a10b3be9a187aef76d4688081dc968b833a Mon Sep 17 00:00:00 2001 From: Jakub Rzeszutko Date: Mon, 26 Nov 2018 16:43:27 +0100 Subject: [PATCH] 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 --- drivers/pci/pci_shell.c | 5 - include/shell/shell.h | 13 -- samples/mpu/mpu_test/src/main.c | 25 --- samples/net/promiscuous_mode/src/main.c | 5 - samples/net/rpl_border_router/src/shell.c | 10 -- samples/net/zperf/src/zperf_shell.c | 18 +- .../shell/shell_module/src/dynamic_cmd.c | 19 +- subsys/logging/log_cmds.c | 2 +- subsys/net/ip/net_shell.c | 163 ------------------ subsys/net/l2/bluetooth/bluetooth_shell.c | 11 +- subsys/net/l2/ieee802154/ieee802154_shell.c | 49 +----- subsys/net/l2/wifi/wifi_shell.c | 12 +- subsys/net/lib/openthread/platform/shell.c | 5 - subsys/shell/shell.c | 45 +++-- subsys/shell/shell_cmds.c | 5 +- 15 files changed, 41 insertions(+), 346 deletions(-) diff --git a/drivers/pci/pci_shell.c b/drivers/pci/pci_shell.c index b1ae3ce79dd..3cf03cab18f 100644 --- a/drivers/pci/pci_shell.c +++ b/drivers/pci/pci_shell.c @@ -44,11 +44,6 @@ static int cmd_lspci(const struct shell *shell, size_t argc, char **argv) .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 b886b5df643..e09caf554b4 100644 --- a/include/shell/shell.h +++ b/include/shell/shell.h @@ -342,7 +342,6 @@ struct shell_stats { */ 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.*/ @@ -615,18 +614,6 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, */ 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. * diff --git a/samples/mpu/mpu_test/src/main.c b/samples/mpu/mpu_test/src/main.c index 0727d812ee0..c3c47278752 100644 --- a/samples/mpu/mpu_test/src/main.c +++ b/samples/mpu/mpu_test/src/main.c @@ -34,11 +34,6 @@ static int cmd_read(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_write_mcux(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_write_stm32(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_write(const struct shell *shell, size_t argc, char *argv[]) /* 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 @@ static int cmd_run(const struct shell *shell, size_t argc, char *argv[]) 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 79f8461482c..d608be16548 100644 --- a/samples/net/promiscuous_mode/src/main.c +++ b/samples/net/promiscuous_mode/src/main.c @@ -146,11 +146,6 @@ static int set_promisc_mode(const struct shell *shell, 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 9b283b33de0..4b2c179eff1 100644 --- a/samples/net/rpl_border_router/src/shell.c +++ b/samples/net/rpl_border_router/src/shell.c @@ -24,11 +24,6 @@ static int cmd_br_repair(const struct shell *shell, 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 @@ static int cmd_coap_send(const struct shell *shell, 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 78378a95180..8c7477c2c72 100644 --- a/samples/net/zperf/src/zperf_shell.c +++ b/samples/net/zperf/src/zperf_shell.c @@ -225,7 +225,7 @@ static int cmd_setip(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_setip(const struct shell *shell, size_t argc, char *argv[]) } 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 @@ static int cmd_setip(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_setip(const struct shell *shell, size_t argc, char *argv[]) "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 @@ static int cmd_udp_download(const struct shell *shell, size_t argc, 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 @@ static int cmd_tcp_download(const struct shell *shell, size_t argc, 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 e61af2e857a..b560c84d0a7 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 @@ extern void qsort(void *a, size_t n, size_t es, cmp_t *cmp); 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 @@ static int cmd_dynamic_add(const struct shell *shell, 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_add(const struct shell *shell, 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_show(const struct shell *shell, 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_execute(const struct shell *shell, 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 ad3a575b1c2..5f7fc7b795a 100644 --- a/subsys/logging/log_cmds.c +++ b/subsys/logging/log_cmds.c @@ -441,7 +441,7 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_log_stat) 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 3fa153c168b..2510212ebd5 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -1152,11 +1152,6 @@ static int cmd_net_allocs(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_app(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_arp(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_arp_flush(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_conn(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_dns_cancel(const struct shell *shell, size_t argc, 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_cancel(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_dns(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_gptp_port(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_gptp(const struct shell *shell, size_t argc, char *argv[]) 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 http_monitor_count; 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 @@ static int cmd_net_http(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_iface_up(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_iface_down(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_ipv6(const struct shell *shell, size_t argc, char *argv[]) #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 @@ static int cmd_net_iface(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_mem(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_nbr_rm(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_nbr(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[]) ARG_UNUSED(argc); - if (shell_help_requested(shell)) { - shell_help_print(shell); - return -ENOEXEC; - } - host = argv[1]; if (!host) { @@ -3306,11 +3208,6 @@ static int cmd_net_route(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_rpl(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_stacks(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_stats_all(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_stats_iface(const struct shell *shell, size_t argc, #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_iface(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_tcp_connect(const struct shell *shell, size_t argc, u16_t port; #endif - if (shell_help_requested(shell)) { - shell_help_print(shell); - return -ENOEXEC; - } - #if defined(CONFIG_NET_TCP) /* tcp connect port */ if (tcp_ctx && net_context_is_used(tcp_ctx)) { @@ -3988,11 +3855,6 @@ static int cmd_net_tcp_send(const struct shell *shell, size_t argc, struct net_pkt *pkt; #endif - if (shell_help_requested(shell)) { - shell_help_print(shell); - return -ENOEXEC; - } - #if defined(CONFIG_NET_TCP) /* tcp send */ if (!tcp_ctx || !net_context_is_used(tcp_ctx)) { @@ -4043,11 +3905,6 @@ static int cmd_net_tcp_close(const struct shell *shell, size_t argc, 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 @@ static int cmd_net_tcp(const struct shell *shell, size_t argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); - if (shell_help_requested(shell)) { - shell_help_print(shell); - return -ENOEXEC; - } - return 0; } @@ -4152,11 +4004,6 @@ static int cmd_net_vlan(const struct shell *shell, size_t argc, char *argv[]) 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 @@ static int cmd_net_vlan_add(const struct shell *shell, size_t argc, u32_t iface_idx; #endif - if (shell_help_requested(shell)) { - shell_help_print(shell); - return -ENOEXEC; - } - #if defined(CONFIG_NET_VLAN) /* vlan add */ if (!argv[++arg]) { @@ -4260,11 +4102,6 @@ static int cmd_net_vlan_del(const struct shell *shell, size_t argc, u16_t tag; #endif - if (shell_help_requested(shell)) { - shell_help_print(shell); - return -ENOEXEC; - } - #if defined(CONFIG_NET_VLAN) /* vlan del */ if (!argv[++arg]) { diff --git a/subsys/net/l2/bluetooth/bluetooth_shell.c b/subsys/net/l2/bluetooth/bluetooth_shell.c index bee2f9e8631..b0a1751ded7 100644 --- a/subsys/net/l2/bluetooth/bluetooth_shell.c +++ b/subsys/net/l2/bluetooth/bluetooth_shell.c @@ -84,7 +84,7 @@ static int shell_cmd_connect(const struct shell *shell, 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 @@ static int shell_cmd_scan(const struct shell *shell, { 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 @@ static int shell_cmd_disconnect(const struct shell *shell, { 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 @@ static int shell_cmd_advertise(const struct shell *shell, { 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 eae37846826..cb7f2279617 100644 --- a/subsys/net/l2/ieee802154/ieee802154_shell.c +++ b/subsys/net/l2/ieee802154/ieee802154_shell.c @@ -36,11 +36,6 @@ static int cmd_ieee802154_ack(const struct shell *shell, 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 @@ static int cmd_ieee802154_associate(const struct shell *shell, 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 @@ static int cmd_ieee802154_disassociate(const struct shell *shell, 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 @@ static int cmd_ieee802154_scan(const struct shell *shell, 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 @@ static int cmd_ieee802154_set_chan(const struct shell *shell, 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 @@ static int cmd_ieee802154_get_chan(const struct shell *shell, 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 @@ static int cmd_ieee802154_set_pan_id(const struct shell *shell, ARG_UNUSED(argc); - if (argc < 2 || shell_help_requested(shell)) { + if (argc < 2) { shell_help_print(shell); return -ENOEXEC; } @@ -393,11 +378,6 @@ static int cmd_ieee802154_get_pan_id(const struct shell *shell, 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 @@ static int cmd_ieee802154_set_ext_addr(const struct shell *shell, 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 @@ static int cmd_ieee802154_get_ext_addr(const struct shell *shell, 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 @@ static int cmd_ieee802154_set_short_addr(const struct shell *shell, 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 @@ static int cmd_ieee802154_get_short_addr(const struct shell *shell, 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 @@ static int cmd_ieee802154_set_tx_power(const struct shell *shell, 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 @@ static int cmd_ieee802154_get_tx_power(const struct shell *shell, 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 e97a48d3c50..2ca1dd52528 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -151,7 +151,7 @@ static int cmd_wifi_connect(const struct shell *shell, size_t argc, 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 @@ static int cmd_wifi_disconnect(const struct shell *shell, size_t argc, 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 @@ static int cmd_wifi_scan(const struct shell *shell, size_t argc, char *argv[]) { 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 ac6cee0c00a..353f5ec5b7f 100644 --- a/subsys/net/lib/openthread/platform/shell.c +++ b/subsys/net/lib/openthread/platform/shell.c @@ -35,11 +35,6 @@ static int ot_cmd(const struct shell *shell, size_t argc, char *argv[]) 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 b3449b8805a..64ce48ef709 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -62,15 +62,6 @@ static inline void transport_buffer_flush(const struct shell *shell) 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 @@ static const struct shell_cmd_entry *root_cmd_find(const char *syntax) 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 @@ static int exec_cmd(const struct shell *shell, size_t argc, char **argv) } 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 @@ static int shell_execute(const struct shell *shell) 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 @@ static int shell_execute(const struct shell *shell) /* 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 @@ static int shell_execute(const struct shell *shell) /* 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 @@ static int shell_execute(const struct shell *shell) "Error: requested" " multiple function" " executions\r\n"); - help_flag_clear(shell); return -ENOEXEC; } @@ -1156,6 +1156,10 @@ static int shell_execute(const struct shell *shell) 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 @@ static int shell_execute(const struct shell *shell) /* 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_prompt_change(const struct shell *shell, char *prompt) 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 e77558dea26..99cc565d495 100644 --- a/subsys/shell/shell_cmds.c +++ b/subsys/shell/shell_cmds.c @@ -434,10 +434,7 @@ static int cmd_shell_stats(const struct shell *shell, size_t argc, char **argv) { 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],