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 <ycsin@meta.com>
This commit is contained in:
Yong Cong Sin 2024-01-18 00:36:58 +08:00 committed by Carles Cufí
parent 2cd0265f7e
commit 45c554d082
6 changed files with 36 additions and 1 deletions

View file

@ -1,4 +1,5 @@
# Copyright (c) 2024 Meta
# SPDX-License-Identifier: Apache-2.0
zephyr_library_sources_ifdef(CONFIG_POSIX_SHELL posix_shell.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME_SHELL uname.c)

View file

@ -3,6 +3,11 @@
if SHELL
config POSIX_SHELL
bool
help
Compile the parent `posix` shell command.
rsource "Kconfig.uname"
endif # SHELL

View file

@ -6,6 +6,7 @@ if POSIX_UNAME
config POSIX_UNAME_SHELL
bool "Support for `uname` command"
select SHELL_GETOPT
select POSIX_SHELL
help
Support for `uname` command in the terminal.

View file

@ -0,0 +1,10 @@
/*
* Copyright (c) 2024 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/shell/shell.h>
SHELL_SUBCMD_SET_CREATE(posix_cmds, (posix));
SHELL_CMD_ARG_REGISTER(posix, &posix_cmds, "POSIX shell commands", NULL, 2, 0);

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2024 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_LIB_POSIX_SHELL_POSIX_SHELL_H_
#define ZEPHYR_LIB_POSIX_SHELL_POSIX_SHELL_H_
#include <zephyr/shell/shell.h>
/* Add command to the set of POSIX subcommands, see `SHELL_SUBCMD_ADD` */
#define POSIX_CMD_ADD(_syntax, _subcmd, _help, _handler, _mand, _opt) \
SHELL_SUBCMD_ADD((posix), _syntax, _subcmd, _help, _handler, _mand, _opt);
#endif /* ZEPHYR_LIB_POSIX_SHELL_POSIX_SHELL_H_ */

View file

@ -6,6 +6,8 @@
#include <unistd.h>
#include "posix_shell.h"
#include <zephyr/posix/sys/utsname.h>
#include <zephyr/shell/shell.h>
@ -168,4 +170,4 @@ static int uname_cmd_handler(const struct shell *sh, size_t argc, char **argv)
return 0;
}
SHELL_CMD_REGISTER(uname, NULL, NULL, uname_cmd_handler);
POSIX_CMD_ADD(uname, NULL, "Print system information", uname_cmd_handler, 1, 1);