1 /*
2  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3  */
4 
5 #include "stdarg.h"
6 #include "aos/cli.h"
7 #include "aos/errno.h"
8 #include "cli_api.h"
9 #include "cli_console.h"
10 
_cli_to_aos_res(int res)11 static int _cli_to_aos_res(int res)
12 {
13     switch (res) {
14         case CLI_OK:
15             return 0;
16         case CLI_ERR_NOMEM:
17             return -ENOMEM;
18         case CLI_ERR_DENIED:
19             return -EPERM;
20         case CLI_ERR_INVALID:
21             return -EINVAL;
22         default:
23             return -EIO;
24     }
25 }
26 
aos_cli_init(void)27 int aos_cli_init(void)
28 {
29     return _cli_to_aos_res(cli_init());
30 }
31 
aos_cli_register_command(const struct cli_command * cmd)32 int aos_cli_register_command(const struct cli_command *cmd)
33 {
34     return _cli_to_aos_res(cli_register_command((struct cli_command *)cmd));
35 }
36 
aos_cli_unregister_command(const struct cli_command * cmd)37 int aos_cli_unregister_command(const struct cli_command *cmd)
38 {
39     return _cli_to_aos_res(cli_unregister_command((struct cli_command *)cmd));
40 }
41 
aos_cli_register_commands(const struct cli_command * cmds,int num)42 int aos_cli_register_commands(const struct cli_command *cmds, int num)
43 {
44     return _cli_to_aos_res(cli_register_commands((struct cli_command *)cmds, num));
45 }
46 
aos_cli_unregister_commands(const struct cli_command * cmds,int num)47 int aos_cli_unregister_commands(const struct cli_command *cmds, int num)
48 {
49     return _cli_to_aos_res(cli_unregister_commands((struct cli_command *)cmds, num));
50 }
51 
aos_cli_printf(const char * fmt,...)52 int aos_cli_printf(const char *fmt, ...)
53 {
54     va_list params;
55     int     ret;
56 
57     va_start(params, fmt);
58     ret = cli_va_printf(fmt, params);
59     va_end(params);
60     return ret;
61 }
62