]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[menu] Add "--default" option to "choose" command
authorMichael Brown <mcb30@ipxe.org>
Sat, 28 Apr 2012 22:18:55 +0000 (23:18 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sat, 28 Apr 2012 22:42:15 +0000 (23:42 +0100)
Suggested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/hci/commands/menu_cmd.c
src/hci/tui/menu_ui.c
src/include/ipxe/menu.h

index 8dac3cb801fd5dbf766ef83490ac18f985b4bf79..ff3b76fabfad3b9e93d800af2c83f4c0f49c3db6 100644 (file)
@@ -194,6 +194,8 @@ struct choose_options {
        const char *menu;
        /** Timeout */
        unsigned int timeout;
+       /** Default selection */
+       const char *select;
        /** Keep menu */
        int keep;
 };
@@ -202,6 +204,8 @@ struct choose_options {
 static struct option_descriptor choose_opts[] = {
        OPTION_DESC ( "menu", 'm', required_argument,
                      struct choose_options, menu, parse_string ),
+       OPTION_DESC ( "default", 'd', required_argument,
+                     struct choose_options, select, parse_string ),
        OPTION_DESC ( "timeout", 't', required_argument,
                      struct choose_options, timeout, parse_integer ),
        OPTION_DESC ( "keep", 'k', no_argument,
@@ -211,8 +215,8 @@ static struct option_descriptor choose_opts[] = {
 /** "choose" command descriptor */
 static struct command_descriptor choose_cmd =
        COMMAND_DESC ( struct choose_options, choose_opts, 1, 1,
-                      "[--menu <menu>] [--timeout <timeout>] [--keep] "
-                      "<setting>" );
+                      "[--menu <menu>] [--default <label>] "
+                      "[--timeout <timeout>] [--keep] <setting>" );
 
 /**
  * The "choose" command
@@ -240,7 +244,7 @@ static int choose_exec ( int argc, char **argv ) {
                goto err_parse_menu;
 
        /* Show menu */
-       if ( ( rc = show_menu ( menu, opts.timeout, &item ) ) != 0 )
+       if ( ( rc = show_menu ( menu, opts.timeout, opts.select, &item ) ) != 0)
                goto err_show_menu;
 
        /* Store setting */
index 2457a82543bc5821d565e65e6aec540c11961f48..30d93ad2fa53fad0953803a2d03f381278aa8cce 100644 (file)
@@ -303,7 +303,7 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
  * @ret rc             Return status code
  */
 int show_menu ( struct menu *menu, unsigned int timeout_ms,
-               struct menu_item **selected ) {
+               const char *select, struct menu_item **selected ) {
        struct menu_item *item;
        struct menu_ui ui;
        int labelled_count = 0;
@@ -318,8 +318,13 @@ int show_menu ( struct menu *menu, unsigned int timeout_ms,
                        if ( ! labelled_count )
                                ui.selected = ui.count;
                        labelled_count++;
-                       if ( item->is_default )
-                               ui.selected = ui.count;
+                       if ( select ) {
+                               if ( strcmp ( select, item->label ) == 0 )
+                                       ui.selected = ui.count;
+                       } else {
+                               if ( item->is_default )
+                                       ui.selected = ui.count;
+                       }
                }
                ui.count++;
        }
index 05bc1d45ebbf108a73d05bf197c3e561a1f57434..993b027ea997eb1971481a466211805f22d0683d 100644 (file)
@@ -44,6 +44,6 @@ extern struct menu_item * add_menu_item ( struct menu *menu, const char *label,
 extern void destroy_menu ( struct menu *menu );
 extern struct menu * find_menu ( const char *name );
 extern int show_menu ( struct menu *menu, unsigned int timeout_ms,
-                      struct menu_item **selected );
+                      const char *select, struct menu_item **selected );
 
 #endif /* _IPXE_MENU_H */