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
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.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
28 * Form parameter commands
35 #include <ipxe/params.h>
36 #include <ipxe/parseopt.h>
37 #include <ipxe/command.h>
39 /** "params" options */
40 struct params_options {
47 /** "params" option list */
48 static struct option_descriptor params_opts[] = {
49 OPTION_DESC ( "name", 'n', required_argument,
50 struct params_options, name, parse_string ),
51 OPTION_DESC ( "delete", 'd', no_argument,
52 struct params_options, delete, parse_flag ),
55 /** "params" command descriptor */
56 static struct command_descriptor params_cmd =
57 COMMAND_DESC ( struct params_options, params_opts, 0, 0, NULL );
60 * The "params" command
62 * @v argc Argument count
63 * @v argv Argument list
64 * @ret rc Return status code
66 static int params_exec ( int argc, char **argv ) {
67 struct params_options opts;
68 struct parameters *params;
72 if ( ( rc = parse_options ( argc, argv, ¶ms_cmd, &opts ) ) != 0)
75 /* Create parameter list */
76 params = create_parameters ( opts.name );
80 /* Destroy parameter list, if applicable */
82 claim_parameters ( params );
83 params_put ( params );
89 /** "param" options */
90 struct param_options {
91 /** Parameter list name */
95 /** "param" option list */
96 static struct option_descriptor param_opts[] = {
97 OPTION_DESC ( "params", 'p', required_argument,
98 struct param_options, params, parse_string ),
101 /** "param" command descriptor */
102 static struct command_descriptor param_cmd =
103 COMMAND_DESC ( struct param_options, param_opts, 1, MAX_ARGUMENTS,
107 * The "param" command
109 * @v argc Argument count
110 * @v argv Argument list
111 * @ret rc Return status code
113 static int param_exec ( int argc, char **argv ) {
114 struct param_options opts;
117 struct parameters *params;
118 struct parameter *param;
122 if ( ( rc = parse_options ( argc, argv, ¶m_cmd, &opts ) ) != 0 )
123 goto err_parse_options;
129 value = concat_args ( &argv[ optind + 1 ] );
132 goto err_parse_value;
135 /* Identify parameter list */
136 if ( ( rc = parse_parameters ( opts.params, ¶ms ) ) != 0 )
137 goto err_parse_parameters;
140 param = add_parameter ( params, key, value );
143 goto err_add_parameter;
150 err_parse_parameters:
157 /** Form parameter commands */
158 struct command param_commands[] __command = {