iPXE
config_cmd.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3 *
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.
8 *
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.
13 *
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
17 * 02110-1301, USA.
18 *
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.
22 */
23
24#include <string.h>
25#include <stdio.h>
26#include <errno.h>
27#include <getopt.h>
28#include <ipxe/command.h>
29#include <ipxe/parseopt.h>
30#include <ipxe/settings.h>
31#include <ipxe/settings_ui.h>
32
33FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
34FILE_SECBOOT ( PERMITTED );
35
36/** @file
37 *
38 * Configuration UI commands
39 *
40 */
41
42/** "config" options */
44
45/** "config" option list */
46static struct option_descriptor config_opts[] = {};
47
48/** "config" command descriptor */
50 COMMAND_DESC ( struct config_options, config_opts, 0, 1, "[<scope>]" );
51
52/**
53 * "config" command
54 *
55 * @v argc Argument count
56 * @v argv Argument list
57 * @ret rc Return status code
58 */
59static int config_exec ( int argc, char **argv ) {
60 struct config_options opts;
61 struct settings *settings;
62 int rc;
63
64 /* Parse options */
65 if ( ( rc = parse_options ( argc, argv, &config_cmd, &opts ) ) != 0 )
66 return rc;
67
68 /* Parse settings option, if present */
69 if ( ( rc = parse_settings ( ( ( optind < argc ) ? argv[optind] : "" ),
70 &settings ) ) != 0 )
71 return rc;
72
73 /* Run settings UI */
74 if ( ( rc = settings_ui ( settings ) ) != 0 ) {
75 printf ( "Could not save settings: %s\n", strerror ( rc ) );
76 return rc;
77 }
78
79 return 0;
80}
81
82/** Configuration UI commands */
83COMMAND ( config, config_exec );
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
#define COMMAND(name, exec)
Definition command.h:27
static int config_exec(int argc, char **argv)
"config" command
Definition config_cmd.c:59
static struct option_descriptor config_opts[]
"config" option list
Definition config_cmd.c:46
static struct command_descriptor config_cmd
"config" command descriptor
Definition config_cmd.c:49
Error codes.
int optind
Current option index.
Definition getopt.c:52
Parse command-line options.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Configuration settings.
String functions.
int parse_settings(char *text, struct settings **value)
Parse settings block name.
Definition parseopt.c:272
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
Command line option parsing.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
Option configuration console.
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A command descriptor.
Definition parseopt.h:78
"config" options
Definition config_cmd.c:43
A command-line option descriptor.
Definition parseopt.h:24
A settings user interface.
A settings block.
Definition settings.h:133
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465