FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
cli.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * cli.h: command line interface
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_vlib_cli_h
41 #define included_vlib_cli_h
42 
43 #include <vppinfra/format.h>
44 
45 struct vlib_cli_command_t;
46 
47 typedef struct
48 {
50 
51  /* Indexed by name[position] - min_char. */
54 
55 typedef struct
56 {
57  u8 *name;
58 
61 
62 typedef struct
63 {
64  u8 *name;
65 
67 
70 
71 typedef struct
72 {
73  char *name;
74  char *short_help;
75  char *long_help;
76 
77  /* Number of bytes in parsed data. Zero for vector. */
79 
81 
82  /* Opaque for unformat function. */
83  uword unformat_function_arg[2];
85 
86 /* CLI command callback function. */
88  (struct vlib_main_t * vm,
89  unformat_input_t * input, struct vlib_cli_command_t * cmd);
90 
91 typedef struct vlib_cli_command_t
92 {
93  /* Command path (e.g. "show something").
94  Spaces delimit elements of path. */
95  char *path;
96 
97  /* Short/long help strings. */
98  char *short_help;
99  char *long_help;
100 
101  /* Callback function. */
103 
104  /* Opaque. */
106 
107  /* Known MP-safe? */
109 
110  /* Sub commands for this command. */
112 
113  /* Hash table mapping name (e.g. last path element) to sub command index. */
115 
116  /* bitmap[p][c][i] says whether sub-command i has character
117  c in position p. */
119 
120  /* Hash table mapping name (e.g. last path element) to sub rule index. */
122 
123  /* Vector of possible parse rules for this path. */
125 
126  /* List of CLI commands, built by constructors */
128 
130 
131 typedef void (vlib_cli_output_function_t) (uword arg,
132  u8 * buffer, uword buffer_bytes);
133 typedef struct
134 {
135  /* Vector of all known commands. */
137 
138  /* Hash table mapping normalized path to index into all_commands. */
140 
141  /* Vector of all known parse rules. */
143 
144  /* Hash table mapping parse rule name to index into parse_rule vector. */
146 
147  /* Data parsed for rules. */
149 
150  /* registration list added by constructors */
153 
154 #ifndef CLIB_MARCH_VARIANT
155 #define VLIB_CLI_COMMAND(x,...) \
156  __VA_ARGS__ vlib_cli_command_t x; \
157 static void __vlib_cli_command_registration_##x (void) \
158  __attribute__((__constructor__)) ; \
159 static void __vlib_cli_command_registration_##x (void) \
160 { \
161  vlib_main_t * vm = vlib_get_main(); \
162  vlib_cli_main_t *cm = &vm->cli_main; \
163  x.next_cli_command = cm->cli_command_registrations; \
164  cm->cli_command_registrations = &x; \
165 } \
166 static void __vlib_cli_command_unregistration_##x (void) \
167  __attribute__((__destructor__)) ; \
168 static void __vlib_cli_command_unregistration_##x (void) \
169 { \
170  vlib_main_t * vm = vlib_get_main(); \
171  vlib_cli_main_t *cm = &vm->cli_main; \
172  VLIB_REMOVE_FROM_LINKED_LIST (cm->cli_command_registrations, &x, \
173  next_cli_command); \
174 } \
175 __VA_ARGS__ vlib_cli_command_t x
176 #else
177 /* create unused pointer to silence compiler warnings and get whole
178  function optimized out */
179 #define VLIB_CLI_COMMAND(x,...) \
180 static __clib_unused vlib_cli_command_t __clib_unused_##x
181 #endif
182 
183 #define VLIB_CLI_PARSE_RULE(x) \
184  vlib_cli_parse_rule_t x
185 /* Output to current CLI connection. */
186 void vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...);
187 
188 /* Process CLI input. */
189 void vlib_cli_input (struct vlib_main_t *vm,
190  unformat_input_t * input,
191  vlib_cli_output_function_t * function,
193 
198 
200 
201 /* Return an vector of strings consisting of possible auto-completions
202  * for a given input string */
203 u8 **vlib_cli_get_possible_completions (u8 * input_str);
204 
205 #endif /* included_vlib_cli_h */
206 
207 /*
208  * fd.io coding-style-patch-verification: ON
209  *
210  * Local Variables:
211  * eval: (c-set-style "gnu")
212  * End:
213  */
unformat_function_t * unformat_function
Definition: cli.h:80
uword data_size
Definition: cli.h:78
vlib_cli_command_t * commands
Definition: cli.h:136
int i
uword * sub_rule_index_by_name
Definition: cli.h:121
unsigned char u8
Definition: types.h:56
clib_error_t * vlib_cli_register_parse_rule(struct vlib_main_t *vm, vlib_cli_parse_rule_t *c)
Definition: cli.c:1485
u8 ** vlib_cli_get_possible_completions(u8 *input_str)
Definition: cli.c:255
uword * command_index_by_path
Definition: cli.h:139
u32 command_index
Definition: cli.h:68
unsigned int u32
Definition: types.h:88
vlib_cli_parse_rule_t * parse_rules
Definition: cli.h:142
vlib_cli_sub_rule_t * sub_rules
Definition: cli.h:124
struct _unformat_input_t unformat_input_t
clib_error_t *() vlib_cli_command_function_t(struct vlib_main_t *vm, unformat_input_t *input, struct vlib_cli_command_t *cmd)
Definition: cli.h:88
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:232
char * long_help
Definition: cli.h:75
uword function_arg
Definition: cli.h:105
vlib_cli_sub_command_t * sub_commands
Definition: cli.h:111
svmdb_client_t * c
clib_error_t * vlib_cli_register(struct vlib_main_t *vm, vlib_cli_command_t *c)
Definition: cli.c:1403
uword ** bitmaps
Definition: cli.h:52
uword unformat_vlib_cli_sub_input(unformat_input_t *i, va_list *args)
Definition: cli.c:158
uword * parse_rule_index_by_name
Definition: cli.h:145
char * long_help
Definition: cli.h:99
uword is_mp_safe
Definition: cli.h:108
char * path
Definition: cli.h:95
uword * sub_command_index_by_name
Definition: cli.h:114
void vlib_cli_output(struct vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
struct vlib_cli_command_t * next_cli_command
Definition: cli.h:127
u64 uword
Definition: types.h:112
void ** parse_rule_data
Definition: cli.h:148
vlib_cli_command_t * cli_command_registrations
Definition: cli.h:151
struct vlib_cli_command_t vlib_cli_command_t
char * short_help
Definition: cli.h:74
vlib_cli_parse_position_t * sub_command_positions
Definition: cli.h:118
void() vlib_cli_output_function_t(uword arg, u8 *buffer, uword buffer_bytes)
Definition: cli.h:131
void vlib_cli_input(struct vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
Definition: cli.c:725
char * short_help
Definition: cli.h:98
u32 rule_index
Definition: cli.h:66