diff options
author | Michael Brown | 2012-04-29 00:18:55 +0200 |
---|---|---|
committer | Michael Brown | 2012-04-29 00:42:15 +0200 |
commit | 838a76a0426844e918d12ae0d2e2ee7622a0eca6 (patch) | |
tree | 075e79823a9deb2690c7312d2acae1f5b8043437 /src/hci | |
parent | [realtek] Support RTL8139 cards within generic Realtek driver (diff) | |
download | ipxe-838a76a0426844e918d12ae0d2e2ee7622a0eca6.tar.gz ipxe-838a76a0426844e918d12ae0d2e2ee7622a0eca6.tar.xz ipxe-838a76a0426844e918d12ae0d2e2ee7622a0eca6.zip |
[menu] Add "--default" option to "choose" command
Suggested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci')
-rw-r--r-- | src/hci/commands/menu_cmd.c | 10 | ||||
-rw-r--r-- | src/hci/tui/menu_ui.c | 11 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/hci/commands/menu_cmd.c b/src/hci/commands/menu_cmd.c index 8dac3cb8..ff3b76fa 100644 --- a/src/hci/commands/menu_cmd.c +++ b/src/hci/commands/menu_cmd.c @@ -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 */ diff --git a/src/hci/tui/menu_ui.c b/src/hci/tui/menu_ui.c index 2457a825..30d93ad2 100644 --- a/src/hci/tui/menu_ui.c +++ b/src/hci/tui/menu_ui.c @@ -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++; } |