Parcourir la source

[menu] Add "--default" option to "choose" command

Suggested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown il y a 12 ans
Parent
révision
838a76a042
3 fichiers modifiés avec 16 ajouts et 7 suppressions
  1. 7
    3
      src/hci/commands/menu_cmd.c
  2. 8
    3
      src/hci/tui/menu_ui.c
  3. 1
    1
      src/include/ipxe/menu.h

+ 7
- 3
src/hci/commands/menu_cmd.c Voir le fichier

@@ -194,6 +194,8 @@ struct choose_options {
194 194
 	const char *menu;
195 195
 	/** Timeout */
196 196
 	unsigned int timeout;
197
+	/** Default selection */
198
+	const char *select;
197 199
 	/** Keep menu */
198 200
 	int keep;
199 201
 };
@@ -202,6 +204,8 @@ struct choose_options {
202 204
 static struct option_descriptor choose_opts[] = {
203 205
 	OPTION_DESC ( "menu", 'm', required_argument,
204 206
 		      struct choose_options, menu, parse_string ),
207
+	OPTION_DESC ( "default", 'd', required_argument,
208
+		      struct choose_options, select, parse_string ),
205 209
 	OPTION_DESC ( "timeout", 't', required_argument,
206 210
 		      struct choose_options, timeout, parse_integer ),
207 211
 	OPTION_DESC ( "keep", 'k', no_argument,
@@ -211,8 +215,8 @@ static struct option_descriptor choose_opts[] = {
211 215
 /** "choose" command descriptor */
212 216
 static struct command_descriptor choose_cmd =
213 217
 	COMMAND_DESC ( struct choose_options, choose_opts, 1, 1,
214
-		       "[--menu <menu>] [--timeout <timeout>] [--keep] "
215
-		       "<setting>" );
218
+		       "[--menu <menu>] [--default <label>] "
219
+		       "[--timeout <timeout>] [--keep] <setting>" );
216 220
 
217 221
 /**
218 222
  * The "choose" command
@@ -240,7 +244,7 @@ static int choose_exec ( int argc, char **argv ) {
240 244
 		goto err_parse_menu;
241 245
 
242 246
 	/* Show menu */
243
-	if ( ( rc = show_menu ( menu, opts.timeout, &item ) ) != 0 )
247
+	if ( ( rc = show_menu ( menu, opts.timeout, opts.select, &item ) ) != 0)
244 248
 		goto err_show_menu;
245 249
 
246 250
 	/* Store setting */

+ 8
- 3
src/hci/tui/menu_ui.c Voir le fichier

@@ -303,7 +303,7 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
303 303
  * @ret rc		Return status code
304 304
  */
305 305
 int show_menu ( struct menu *menu, unsigned int timeout_ms,
306
-		struct menu_item **selected ) {
306
+		const char *select, struct menu_item **selected ) {
307 307
 	struct menu_item *item;
308 308
 	struct menu_ui ui;
309 309
 	int labelled_count = 0;
@@ -318,8 +318,13 @@ int show_menu ( struct menu *menu, unsigned int timeout_ms,
318 318
 			if ( ! labelled_count )
319 319
 				ui.selected = ui.count;
320 320
 			labelled_count++;
321
-			if ( item->is_default )
322
-				ui.selected = ui.count;
321
+			if ( select ) {
322
+				if ( strcmp ( select, item->label ) == 0 )
323
+					ui.selected = ui.count;
324
+			} else {
325
+				if ( item->is_default )
326
+					ui.selected = ui.count;
327
+			}
323 328
 		}
324 329
 		ui.count++;
325 330
 	}

+ 1
- 1
src/include/ipxe/menu.h Voir le fichier

@@ -44,6 +44,6 @@ extern struct menu_item * add_menu_item ( struct menu *menu, const char *label,
44 44
 extern void destroy_menu ( struct menu *menu );
45 45
 extern struct menu * find_menu ( const char *name );
46 46
 extern int show_menu ( struct menu *menu, unsigned int timeout_ms,
47
-		       struct menu_item **selected );
47
+		       const char *select, struct menu_item **selected );
48 48
 
49 49
 #endif /* _IPXE_MENU_H */

Chargement…
Annuler
Enregistrer