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, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
21 #include <helper/log.h>
23 COMMAND_HANDLER(handle_foo_command
)
25 if (CMD_ARGC
< 1 || CMD_ARGC
> 2)
26 return ERROR_COMMAND_SYNTAX_ERROR
;
29 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], address
);
31 const char *msg
= "<unchanged>";
34 COMMAND_PARSE_ENABLE(CMD_ARGV
[1], enable
);
35 msg
= enable
? "enable" : "disable";
38 LOG_INFO("%s: address=0x%8.8" PRIx32
" enabled=%s", CMD_NAME
, address
, msg
);
44 COMMAND_HANDLER(handle_flag_command
)
46 return CALL_COMMAND_HANDLER(handle_command_parse_bool
,
47 &foo_flag
, "foo flag");
50 static const struct command_registration foo_command_handlers
[] = {
53 .handler
= &handle_foo_command
,
55 .usage
= "address ['enable'|'disable']",
56 .help
= "an example command",
60 .handler
= &handle_foo_command
,
62 .usage
= "address ['enable'|'disable']",
63 .help
= "a sample command",
67 .handler
= &handle_flag_command
,
72 COMMAND_REGISTRATION_DONE
75 static COMMAND_HELPER(handle_hello_args
, const char **sep
, const char **name
)
78 return ERROR_COMMAND_SYNTAX_ERROR
;
87 COMMAND_HANDLER(handle_hello_command
)
89 const char *sep
, *name
;
90 int retval
= CALL_COMMAND_HANDLER(handle_hello_args
, &sep
, &name
);
91 if (ERROR_OK
== retval
)
92 command_print(CMD_CTX
, "Greetings%s%s!", sep
, name
);
96 const struct command_registration hello_command_handlers
[] = {
99 .handler
= handle_hello_command
,
101 .help
= "prints a warm welcome",
107 .help
= "example command handler skeleton",
109 .chain
= foo_command_handlers
,
111 COMMAND_REGISTRATION_DONE