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 claim_parameters ( params );
79 params_put ( params );
85 /** "param" options */
86 struct param_options {
87 /** Parameter list name */
91 /** "param" option list */
92 static struct option_descriptor param_opts[] = {
93 OPTION_DESC ( "params", 'p', required_argument,
94 struct param_options, params, parse_string ),
97 /** "param" command descriptor */
98 static struct command_descriptor param_cmd =
99 COMMAND_DESC ( struct param_options, param_opts, 1, MAX_ARGUMENTS,
103 * The "param" command
105 * @v argc Argument count
106 * @v argv Argument list
107 * @ret rc Return status code
109 static int param_exec ( int argc, char **argv ) {
110 struct param_options opts;
113 struct parameters *params;
114 struct parameter *param;
118 if ( ( rc = parse_options ( argc, argv, ¶m_cmd, &opts ) ) != 0 )
119 goto err_parse_options;
125 value = concat_args ( &argv[ optind + 1 ] );
128 goto err_parse_value;
131 /* Identify parameter list */
132 if ( ( rc = parse_parameters ( opts.params, ¶ms ) ) != 0 )
133 goto err_parse_parameters;
136 param = add_parameter ( params, key, value );
139 goto err_add_parameter;
146 err_parse_parameters:
153 /** Form parameter commands */
154 struct command param_commands[] __command = {