summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-09-17 15:45:53 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-09-20 08:58:52 +0200
commit7923392c561136bd7ac3d9e28cc61c18be3a8b3f (patch)
tree623a6239c8eebb4e4ae6f6d6ee0b50bf15f63c78 /commands
parent3212e8462e876bd47fa14a0ba9fd455f37458d52 (diff)
downloadbarebox-7923392c561136bd7ac3d9e28cc61c18be3a8b3f.tar.gz
barebox-7923392c561136bd7ac3d9e28cc61c18be3a8b3f.tar.xz
menu: add auto select support
this will allow to automaticaly run an entry if the user do no choice this is usefull for boot menu as example with menu -s -m boot -A 3 -d "Auto Boot in" Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/menu.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/commands/menu.c b/commands/menu.c
index 7b8e8bec58..d2ac5cdb24 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -48,11 +48,12 @@ struct cmd_menu {
char *command;
char *submenu;
int num;
+ int auto_select;
#endif
};
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
-#define OPTS "m:earlc:d:RsSn:u:"
+#define OPTS "m:earlc:d:RsSn:u:A:"
#define is_entry(x) ((x)->entry)
#else
#define OPTS "m:ls"
@@ -212,7 +213,7 @@ static int do_menu_select(struct cmd_menu *cm)
#endif
/*
- * menu -s -m <menu>
+ * menu -s -m <menu> [-A <auto select delay>] [-d <display]
*/
static int do_menu_show(struct cmd_menu *cm)
{
@@ -223,6 +224,17 @@ static int do_menu_show(struct cmd_menu *cm)
else
m = menu_get_by_name("boot");
+ if (!m)
+ return -EINVAL;
+
+ if (cm->auto_select != -EINVAL) {
+ menu_set_auto_select(m, cm->auto_select);
+
+ free(m->auto_display);
+
+ m->auto_display = strdup(cm->description);
+ }
+
return menu_show(m);
}
@@ -300,6 +312,7 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
memset(&cm, 0, sizeof(struct cmd_menu));
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
cm.num = -EINVAL;
+ cm.auto_select = -EINVAL;
#endif
cm.action = action_show;
@@ -343,6 +356,9 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
case 'n':
cm.num = simple_strtoul(optarg, NULL, 10);
break;
+ case 'A':
+ cm.auto_select = simple_strtoul(optarg, NULL, 10);
+ break;
#endif
default:
return 1;
@@ -398,7 +414,9 @@ static const __maybe_unused char cmd_menu_help[] =
"How to\n"
"\n"
"Show menu\n"
-" menu -s -m <menu>\n"
+" (-A auto select delay)\n"
+" (-d auto select description)\n"
+" menu -s -m <menu> [-A delay] [-d auto_display]\n"
"\n"
"List menu\n"
" menu -l\n"