Skip to content

Commit 45c554d

Browse files
ycsincarlescufi
authored andcommitted
posix: shell: introduce top level posix command
Added a top level `posix` shell command for other POSIX commands. Currently only `uname` is supported. New POSIX commands can be added by including the `posix_shell.h` header and use the `POSIX_CMD_ADD` helper macro. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent 2cd0265 commit 45c554d

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

lib/posix/shell/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2024 Meta
22
# SPDX-License-Identifier: Apache-2.0
33

4+
zephyr_library_sources_ifdef(CONFIG_POSIX_SHELL posix_shell.c)
45
zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME_SHELL uname.c)

lib/posix/shell/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
if SHELL
55

6+
config POSIX_SHELL
7+
bool
8+
help
9+
Compile the parent `posix` shell command.
10+
611
rsource "Kconfig.uname"
712

813
endif # SHELL

lib/posix/shell/Kconfig.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if POSIX_UNAME
66
config POSIX_UNAME_SHELL
77
bool "Support for `uname` command"
88
select SHELL_GETOPT
9+
select POSIX_SHELL
910
help
1011
Support for `uname` command in the terminal.
1112

lib/posix/shell/posix_shell.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2024 Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/shell/shell.h>
8+
9+
SHELL_SUBCMD_SET_CREATE(posix_cmds, (posix));
10+
SHELL_CMD_ARG_REGISTER(posix, &posix_cmds, "POSIX shell commands", NULL, 2, 0);

lib/posix/shell/posix_shell.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2024 Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_LIB_POSIX_SHELL_POSIX_SHELL_H_
8+
#define ZEPHYR_LIB_POSIX_SHELL_POSIX_SHELL_H_
9+
10+
#include <zephyr/shell/shell.h>
11+
12+
/* Add command to the set of POSIX subcommands, see `SHELL_SUBCMD_ADD` */
13+
#define POSIX_CMD_ADD(_syntax, _subcmd, _help, _handler, _mand, _opt) \
14+
SHELL_SUBCMD_ADD((posix), _syntax, _subcmd, _help, _handler, _mand, _opt);
15+
16+
#endif /* ZEPHYR_LIB_POSIX_SHELL_POSIX_SHELL_H_ */

lib/posix/shell/uname.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <unistd.h>
88

9+
#include "posix_shell.h"
10+
911
#include <zephyr/posix/sys/utsname.h>
1012
#include <zephyr/shell/shell.h>
1113

@@ -168,4 +170,4 @@ static int uname_cmd_handler(const struct shell *sh, size_t argc, char **argv)
168170
return 0;
169171
}
170172

171-
SHELL_CMD_REGISTER(uname, NULL, NULL, uname_cmd_handler);
173+
POSIX_CMD_ADD(uname, NULL, "Print system information", uname_cmd_handler, 1, 1);

0 commit comments

Comments
 (0)