2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31 #include <readline/readline.h>
32 #include <ipxe/command.h>
33 #include <ipxe/parseopt.h>
34 #include <ipxe/shell.h>
35 #include <config/branding.h>
39 * Minimal command shell
43 /** The shell prompt string */
44 static const char shell_prompt[] = PRODUCT_SHORT_NAME "> ";
49 * @v argc Argument count
50 * @v argv Argument list
51 * @ret rc Return status code
53 static int help_exec ( int argc __unused, char **argv __unused ) {
54 struct command *command;
55 unsigned int hpos = 0;
57 printf ( "\nAvailable commands:\n\n" );
58 for_each_table_entry ( command, COMMANDS ) {
59 hpos += printf ( " %s", command->name );
60 if ( hpos > ( 16 * 4 ) ) {
70 printf ( "\n\nType \"<command> --help\" for further information\n\n" );
75 struct command help_command __command = {
85 struct readline_history history;
89 /* Initialise shell history */
90 memset ( &history, 0, sizeof ( history ) );
92 /* Read and execute commands */
94 readline_history ( shell_prompt, NULL, &history, &line );
99 } while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );
101 /* Discard shell history */
102 history_free ( &history );
107 /** "shell" options */
108 struct shell_options {};
110 /** "shell" option list */
111 static struct option_descriptor shell_opts[] = {};
113 /** "shell" command descriptor */
114 static struct command_descriptor shell_cmd =
115 COMMAND_DESC ( struct shell_options, shell_opts, 0, 0, NULL );
120 * @v argc Argument count
121 * @v argv Argument list
122 * @ret rc Return status code
124 static int shell_exec ( int argc, char **argv ) {
125 struct shell_options opts;
129 if ( ( rc = parse_options ( argc, argv, &shell_cmd, &opts ) ) != 0 )
133 if ( ( rc = shell() ) != 0 )
139 /** "shell" command */
140 struct command shell_command __command = {