const char *menu;
/** Timeout */
unsigned int timeout;
+ /** Default selection */
+ const char *select;
/** Keep menu */
int keep;
};
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,
/** "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
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 */
* @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;
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++;
}
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 */