Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / lib / shell / commands.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 /**
19  *    @file
20  *      Source implementation of default shell commands for CHIP examples.
21  */
22
23 #include "CHIPVersion.h"
24
25 #include "shell.h"
26 #include <support/CodeUtils.h>
27
28 #include <assert.h>
29 #include <ctype.h>
30 #include <errno.h>
31 #include <stdint.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 namespace chip {
36 namespace Shell {
37
38 int cmd_exit(int argc, char ** argv)
39 {
40     streamer_printf(streamer_get(), "Goodbye\n\r");
41     exit(0);
42     return 0;
43 }
44
45 int cmd_help_iterator(shell_command_t * command, void * arg)
46 {
47     streamer_printf(streamer_get(), "  %-15s %s\n\r", command->cmd_name, command->cmd_help);
48     return 0;
49 }
50
51 int cmd_help(int argc, char ** argv)
52 {
53     shell_command_foreach(cmd_help_iterator, nullptr);
54     return 0;
55 }
56
57 int cmd_version(int argc, char ** argv)
58 {
59     streamer_printf(streamer_get(), "CHIP %s\n\r", CHIP_VERSION_STRING);
60     return 0;
61 }
62
63 static shell_command_t cmds[] = {
64     { &cmd_exit, "exit", "Exit the shell application" },
65     { &cmd_help, "help", "List out all top level commands" },
66     { &cmd_version, "version", "Output the software version" },
67 };
68
69 void Shell::RegisterDefaultCommands()
70 {
71     RegisterCommands(cmds, ArraySize(cmds));
72 }
73
74 } // namespace Shell
75 } // namespace chip