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>
13 COMMAND_HANDLER(handle_foo_command
)
15 if (CMD_ARGC
< 1 || CMD_ARGC
> 2)
16 return ERROR_COMMAND_SYNTAX_ERROR
;
19 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], address
);
21 const char *msg
= "<unchanged>";
24 COMMAND_PARSE_ENABLE(CMD_ARGV
[1], enable
);
25 msg
= enable
? "enable" : "disable";
28 LOG_INFO("%s: address=0x%8.8" PRIx32
" enabled=%s", CMD_NAME
, address
, msg
);
34 COMMAND_HANDLER(handle_flag_command
)
36 return CALL_COMMAND_HANDLER(handle_command_parse_bool
,
37 &foo_flag
, "foo flag");
40 static const struct command_registration foo_command_handlers
[] = {
43 .handler
= &handle_foo_command
,
45 .usage
= "address ['enable'|'disable']",
46 .help
= "an example command",
50 .handler
= &handle_foo_command
,
52 .usage
= "address ['enable'|'disable']",
53 .help
= "a sample command",
57 .handler
= &handle_flag_command
,
62 COMMAND_REGISTRATION_DONE
65 static COMMAND_HELPER(handle_hello_args
, const char **sep
, const char **name
)
68 return ERROR_COMMAND_SYNTAX_ERROR
;
77 COMMAND_HANDLER(handle_hello_command
)
79 const char *sep
, *name
;
80 int retval
= CALL_COMMAND_HANDLER(handle_hello_args
, &sep
, &name
);
81 if (retval
== ERROR_OK
)
82 command_print(CMD
, "Greetings%s%s!", sep
, name
);
86 const struct command_registration hello_command_handlers
[] = {
89 .handler
= handle_hello_command
,
91 .help
= "prints a warm welcome",
97 .help
= "example command handler skeleton",
98 .chain
= foo_command_handlers
,
101 COMMAND_REGISTRATION_DONE