2
* Copyright (C) 2013 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 );
24
* Form parameter commands
31
#include <ipxe/params.h>
32
#include <ipxe/parseopt.h>
33
#include <ipxe/command.h>
35
/** "params" options */
36
struct params_options {
43
/** "params" option list */
44
static struct option_descriptor params_opts[] = {
45
OPTION_DESC ( "name", 'n', required_argument,
46
struct params_options, name, parse_string ),
47
OPTION_DESC ( "delete", 'd', no_argument,
48
struct params_options, delete, parse_flag ),
51
/** "params" command descriptor */
52
static struct command_descriptor params_cmd =
53
COMMAND_DESC ( struct params_options, params_opts, 0, 0, NULL );
56
* The "params" command
58
* @v argc Argument count
59
* @v argv Argument list
60
* @ret rc Return status code
62
static int params_exec ( int argc, char **argv ) {
63
struct params_options opts;
64
struct parameters *params;
68
if ( ( rc = parse_options ( argc, argv, ¶ms_cmd, &opts ) ) != 0)
71
/* Create parameter list */
72
params = create_parameters ( opts.name );
76
/* Destroy parameter list, if applicable */
78
destroy_parameters ( params );
83
/** "param" options */
84
struct param_options {
85
/** Parameter list name */
89
/** "param" option list */
90
static struct option_descriptor param_opts[] = {
91
OPTION_DESC ( "params", 'p', required_argument,
92
struct param_options, params, parse_string ),
95
/** "param" command descriptor */
96
static struct command_descriptor param_cmd =
97
COMMAND_DESC ( struct param_options, param_opts, 1, MAX_ARGUMENTS,
101
* The "param" command
103
* @v argc Argument count
104
* @v argv Argument list
105
* @ret rc Return status code
107
static int param_exec ( int argc, char **argv ) {
108
struct param_options opts;
111
struct parameters *params;
112
struct parameter *param;
116
if ( ( rc = parse_options ( argc, argv, ¶m_cmd, &opts ) ) != 0 )
117
goto err_parse_options;
123
value = concat_args ( &argv[ optind + 1 ] );
126
goto err_parse_value;
129
/* Identify parameter list */
130
if ( ( rc = parse_parameters ( opts.params, ¶ms ) ) != 0 )
131
goto err_parse_parameters;
134
param = add_parameter ( params, key, value );
137
goto err_add_parameter;
144
err_parse_parameters:
151
/** Form parameter commands */
152
struct command param_commands[] __command = {