1 /***************************************************************************
2 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU 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 *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
23 #include <helper/log.h>
25 COMMAND_HANDLER(handle_foo_command
)
27 if (CMD_ARGC
< 1 || CMD_ARGC
> 2)
29 return ERROR_COMMAND_SYNTAX_ERROR
;
33 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], address
);
35 const char *msg
= "<unchanged>";
39 COMMAND_PARSE_ENABLE(CMD_ARGV
[1], enable
);
40 msg
= enable
? "enable" : "disable";
43 LOG_INFO("%s: address=0x%8.8" PRIx32
" enabled=%s", CMD_NAME
, address
, msg
);
49 COMMAND_HANDLER(handle_flag_command
)
51 return CALL_COMMAND_HANDLER(handle_command_parse_bool
,
52 &foo_flag
, "foo flag");
55 static const struct command_registration foo_command_handlers
[] = {
58 .handler
= &handle_foo_command
,
60 .usage
= "address ['enable'|'disable']",
61 .help
= "an example command",
65 .handler
= &handle_foo_command
,
67 .usage
= "address ['enable'|'disable']",
68 .help
= "a sample command",
72 .handler
= &handle_flag_command
,
77 COMMAND_REGISTRATION_DONE
80 static COMMAND_HELPER(handle_hello_args
, const char **sep
, const char **name
)
84 return ERROR_COMMAND_SYNTAX_ERROR
;
96 COMMAND_HANDLER(handle_hello_command
)
98 const char *sep
, *name
;
99 int retval
= CALL_COMMAND_HANDLER(handle_hello_args
, &sep
, &name
);
100 if (ERROR_OK
== retval
)
101 command_print(CMD_CTX
, "Greetings%s%s!", sep
, name
);
105 const struct command_registration hello_command_handlers
[] = {
108 .handler
= handle_hello_command
,
110 .help
= "prints a warm welcome",
116 .help
= "example command handler skeleton",
118 .chain
= foo_command_handlers
,
120 COMMAND_REGISTRATION_DONE