iPXE
config_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 #include <string.h>
00025 #include <stdio.h>
00026 #include <errno.h>
00027 #include <getopt.h>
00028 #include <ipxe/command.h>
00029 #include <ipxe/parseopt.h>
00030 #include <ipxe/settings.h>
00031 #include <ipxe/settings_ui.h>
00032 
00033 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00034 
00035 /** @file
00036  *
00037  * Configuration UI commands
00038  *
00039  */
00040 
00041 /** "config" options */
00042 struct config_options {};
00043 
00044 /** "config" option list */
00045 static struct option_descriptor config_opts[] = {};
00046 
00047 /** "config" command descriptor */
00048 static struct command_descriptor config_cmd =
00049         COMMAND_DESC ( struct config_options, config_opts, 0, 1, "[<scope>]" );
00050 
00051 /**
00052  * "config" command
00053  *
00054  * @v argc              Argument count
00055  * @v argv              Argument list
00056  * @ret rc              Return status code
00057  */
00058 static int config_exec ( int argc, char **argv ) {
00059         struct config_options opts;
00060         struct settings *settings;
00061         int rc;
00062 
00063         /* Parse options */
00064         if ( ( rc = parse_options ( argc, argv, &config_cmd, &opts ) ) != 0 )
00065                 return rc;
00066 
00067         /* Parse settings option, if present */
00068         if ( ( rc = parse_settings ( ( ( optind < argc ) ? argv[optind] : "" ),
00069                                      &settings ) ) != 0 )
00070                 return rc;
00071 
00072         /* Run settings UI */
00073         if ( ( rc = settings_ui ( settings ) ) != 0 ) {
00074                 printf ( "Could not save settings: %s\n", strerror ( rc ) );
00075                 return rc;
00076         }
00077 
00078         return 0;
00079 }
00080 
00081 /** Configuration UI commands */
00082 struct command config_command __command = {
00083         .name = "config",
00084         .exec = config_exec,
00085 };