shared/shell: Print out help if using invalid command
PATCH 1/1 shared/shell: Print out help if using invalid command
Because Vincent Petry kindly reported that it is hard to use a command in a submenu, clients are changed to print out help messages as below when an invalid command is used.
[bluetooth]# list-attributes
Invalid command in menu main: list-attributes
Use "help" for a list of available commands in a menu. Use "menu <submenu>" if you want to enter any submenu. Use "back" if you want to return to menu main.
--- src/shared/shell.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
src/shared/shell.c +15 -2
@@ -191,6 +191,15 @@ static const struct bt_shell_menu_entry default_menu[] = { { } }; +static void shell_print_help (void ) +{ +print_text (COLOR_HIGHLIGHT , +"\n" +"Use \"help\" for a list of available commands in a menu.\n" +"Use \"menu <submenu>\" if you want to enter any submenu.\n" +"Use \"back\" if you want to return to menu main." ); +} +static void shell_print_menu (void ) {const struct bt_shell_menu_entry *entry;
@@ -341,8 +350,12 @@ static void shell_exec(int argc, char *argv[])return ;if (menu_exec (default_menu, argc, argv) == -ENOENT ) { -if (menu_exec (data.menu->entries, argc, argv) == -ENOENT ) -print_text (COLOR_HIGHLIGHT ,"Invalid command" ); +if (menu_exec (data.menu->entries, argc, argv) == -ENOENT ) { +print_text (COLOR_HIGHLIGHT , +"Invalid command in menu %s: %s" , + data.menu->name , argv[0 ]); +shell_print_help (); + } } }
Signature · 1 line
2.14.1
Hi Eramoto,
Quoted 50 lines · ERAMOTO Masaya
Because Vincent Petry kindly reported that it is hard to use a command in a submenu, clients are changed to print out help messages as below when an invalid command is used.
[bluetooth]# list-attributes
Invalid command in menu main: list-attributesUse "help" for a list of available commands in a menu. Use "menu <submenu>" if you want to enter any submenu. Use "back" if you want to return to menu main.
--- src/shared/shell.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)src/shared/shell.c +15
-3@@ -191,6 +191,15 @@ static const struct bt_shell_menu_entry default_menu[] = { { } }; +static void shell_print_help (void ) +{ +print_text (COLOR_HIGHLIGHT , +"\n" +"Use \"help\" for a list of available commands in a menu.\n" +"Use \"menu <submenu>\" if you want to enter any submenu.\n" +"Use \"back\" if you want to return to menu main." ); +} +static void shell_print_menu (void ) {const struct bt_shell_menu_entry *entry;@@ -341,8 +350,12 @@ static void shell_exec(int argc, char *argv[])return ;if (menu_exec (default_menu, argc, argv) == -ENOENT ) { -if (menu_exec (data.menu->entries, argc, argv) == -ENOENT ) -print_text (COLOR_HIGHLIGHT ,"Invalid command" ); +if (menu_exec (data.menu->entries, argc, argv) == -ENOENT ) { +print_text (COLOR_HIGHLIGHT , +"Invalid command in menu %s: %s" , + data.menu->name , argv[0 ]); +shell_print_help (); + } } } --
Quoted 1 line
2.14.1
Applied.
Signature · 1 line
Luiz Augusto von Dentz