1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
5 ***************************************************************************/
10 #include <helper/log.h>
12 COMMAND_HANDLER(handle_foo_command
)
14 if (CMD_ARGC
< 1 || CMD_ARGC
> 2)
15 return ERROR_COMMAND_SYNTAX_ERROR
;
18 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], address
);
20 const char *msg
= "<unchanged>";
23 COMMAND_PARSE_ENABLE(CMD_ARGV
[1], enable
);
24 msg
= enable
? "enable" : "disable";
27 LOG_INFO("%s: address=0x%8.8" PRIx32
" enabled=%s", CMD_NAME
, address
, msg
);
33 COMMAND_HANDLER(handle_flag_command
)
35 return CALL_COMMAND_HANDLER(handle_command_parse_bool
,
36 &foo_flag
, "foo flag");
39 static const struct command_registration foo_command_handlers
[] = {
42 .handler
= &handle_foo_command
,
44 .usage
= "address ['enable'|'disable']",
45 .help
= "an example command",
49 .handler
= &handle_foo_command
,
51 .usage
= "address ['enable'|'disable']",
52 .help
= "a sample command",
56 .handler
= &handle_flag_command
,
61 COMMAND_REGISTRATION_DONE
64 static COMMAND_HELPER(handle_hello_args
, const char **sep
, const char **name
)
67 return ERROR_COMMAND_SYNTAX_ERROR
;
76 COMMAND_HANDLER(handle_hello_command
)
78 const char *sep
, *name
;
79 int retval
= CALL_COMMAND_HANDLER(handle_hello_args
, &sep
, &name
);
80 if (retval
== ERROR_OK
)
81 command_print(CMD
, "Greetings%s%s!", sep
, name
);
85 const struct command_registration hello_command_handlers
[] = {
88 .handler
= handle_hello_command
,
90 .help
= "prints a warm welcome",
96 .help
= "example command handler skeleton",
97 .chain
= foo_command_handlers
,
100 COMMAND_REGISTRATION_DONE