1 /*
2  * Copyright (c) 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr.h>
8 #include <shell/shell.h>
9 #include <shell/shell_getopt.h>
10 
z_shell_getopt_init(struct getopt_state * state)11 void z_shell_getopt_init(struct getopt_state *state)
12 {
13 	getopt_init(state);
14 }
15 
shell_getopt(const struct shell * shell,int argc,char * const argv[],const char * ostr)16 int shell_getopt(const struct shell *shell, int argc, char *const argv[],
17 		 const char *ostr)
18 {
19 	if (!IS_ENABLED(CONFIG_SHELL_GETOPT)) {
20 		return 0;
21 	}
22 
23 	__ASSERT_NO_MSG(shell);
24 
25 	return getopt(&shell->ctx->getopt_state, argc, argv, ostr);
26 }
27 
shell_getopt_state_get(const struct shell * shell)28 struct getopt_state *shell_getopt_state_get(const struct shell *shell)
29 {
30 	if (!IS_ENABLED(CONFIG_SHELL_GETOPT)) {
31 		return NULL;
32 	}
33 
34 	__ASSERT_NO_MSG(shell);
35 
36 	return &shell->ctx->getopt_state;
37 }
38