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
20 FILE_LICENCE ( GPL2_OR_LATER );
27 #include <readline/readline.h>
28 #include <ipxe/command.h>
29 #include <ipxe/parseopt.h>
30 #include <ipxe/shell.h>
34 * Minimal command shell
38 /** The shell prompt string */
39 static const char shell_prompt[] = "iPXE> ";
44 * @v argc Argument count
45 * @v argv Argument list
46 * @ret rc Return status code
48 static int help_exec ( int argc __unused, char **argv __unused ) {
49 struct command *command;
50 unsigned int hpos = 0;
52 printf ( "\nAvailable commands:\n\n" );
53 for_each_table_entry ( command, COMMANDS ) {
54 hpos += printf ( " %s", command->name );
55 if ( hpos > ( 16 * 4 ) ) {
65 printf ( "\n\nType \"<command> --help\" for further information\n\n" );
70 struct command help_command __command = {
80 struct readline_history history;
84 /* Initialise shell history */
85 memset ( &history, 0, sizeof ( history ) );
87 /* Read and execute commands */
89 readline_history ( shell_prompt, NULL, &history, &line );
94 } while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );
96 /* Discard shell history */
97 history_free ( &history );
102 /** "shell" options */
103 struct shell_options {};
105 /** "shell" option list */
106 static struct option_descriptor shell_opts[] = {};
108 /** "shell" command descriptor */
109 static struct command_descriptor shell_cmd =
110 COMMAND_DESC ( struct shell_options, shell_opts, 0, 0, NULL );
115 * @v argc Argument count
116 * @v argv Argument list
117 * @ret rc Return status code
119 static int shell_exec ( int argc, char **argv ) {
120 struct shell_options opts;
124 if ( ( rc = parse_options ( argc, argv, &shell_cmd, &opts ) ) != 0 )
128 if ( ( rc = shell() ) != 0 )
134 /** "shell" command */
135 struct command shell_command __command = {