Command Line Interface
- group CLI
Provide the functionalities of command line interface.
Command line interface provides a prompt where the user types a command, which is expressed as a sequence of characters - typically a command name followed by some parameters, and presses the Return key to execute that command.
Typedefs
-
typedef bool (*P_CLI_CALLBACK)(const char *cmd_str, char *p_buf, size_t buf_len)
Define the prototype of command line callback function.
cli.h
- Param cmd_str:
[in] The entire string (including params) as input by the user.
- Param p_buf:
[in] The buffer into which the output from executing the command can be written.
- Param buf_len:
[in] The length in bytes of the p_buf buffer.
- Retval true:
The callback function should be invoked continuously.
- Retval false:
The callback function was completed.
- Return:
Return true if the callback function should be invoked continuously, or false if the callback function is completed.
-
typedef bool (*P_CLI_MATCH)(const char *cmd_str, const char *p_cmd, size_t cmd_len)
Define the prototype of command line pattern matching.
cli.h
- Param cmd_str:
[in] The entire string (including params) as input by the user.
- Param p_cmd:
[in] The command pattern matching buffer.
- Param cmd_len:
[in] The length in bytes of the p_cmd buffer.
- Retval true:
The command pattern was matched.
- Retval false:
The command pattern was failed to match.
- Return:
The status of matching the command pattern.
Functions
-
bool cli_cmd_register(T_CLI_CMD *const cli_cmd)
Register the command passed in using the cli_cmd parameter.
cli.h
Registering a command adds the command to the list of commands that are handled by the command interpreter. Once a command has been registered it can be executed from the command line.
- Parameters:
cli_cmd – [in] The registered command T_CLI_CMD.
- Return values:
true – The command was registered successfully.
false – The command was failed to register.
- Returns:
The status of registering the command.
-
const char *cli_param_get(const char *cmd_str, uint32_t param_idx, uint32_t *param_len)
Get the pointer to the param_idx’th word in the command string.
cli.h
- Parameters:
cmd_str – [in] The start address of the command string.
param_idx – [in] The parameter index in the command string.
param_len – [out] The length of the parameter word.
- Returns:
A pointer to the param_idx’th word in the command string.
-
int32_t cli_param_num_get(const char *cmd_str)
Get the number of parameters that follow the command name.
cli.h
- Parameters:
cmd_str – [in] The start address of the command string.
- Returns:
The number of parameters that follow the command name.
-
bool cli_help_set(const T_CLI_CMD *cmd_list, const char *cmd_str, char *buf, size_t buf_len)
Traverse and echo the help prompts of the specified command list.
cli.h
- Parameters:
cmd_list – [in] The command of which the subcommand list will be traversed.
cmd_str – [in] The entire string (including parameters) as input by the user.
buf – [in] The buffer into which the output from executing the command can be written.
buf_len – [in] The length in bytes of the buffer.
- Return values:
true – The help prompts were traversed and echoed successfully.
false – The help prompts were failed to traverse and echo.
- Returns:
The status of traversing and echoing the help prompts of the specified command list.
-
struct t_cli_cmd
Define the structure of command line interface.
cli.h
Public Members
-
const char *const p_cmd
The command that causes p_callback to be executed.
-
const char *const p_help
String that describes how to use the command.
-
const P_CLI_CALLBACK p_callback
The command callback that will generate output.
-
int32_t param_num
The command expects a fixed number of parameters.
-
const P_CLI_MATCH p_match
The command pattern matching function; NULL if using default match pattern.
-
const char *const p_cmd
-
typedef bool (*P_CLI_CALLBACK)(const char *cmd_str, char *p_buf, size_t buf_len)