]>
git.proxmox.com Git - mirror_frr.git/blob - lib/command_match.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Input matching routines for CLI backend.
6 * Copyright (C) 2016 Cumulus Networks, Inc.
9 #ifndef _ZEBRA_COMMAND_MATCH_H
10 #define _ZEBRA_COMMAND_MATCH_H
20 /* These definitions exist in command.c in the current engine but should be
21 * relocated here in the new engine
23 enum cmd_filter_type
{ FILTER_RELAXED
, FILTER_STRICT
};
25 /* matcher result value */
33 /* completion match types */
35 trivial_match
, // the input is null
36 no_match
, // the input does not match
37 partly_match
, // the input matches but is incomplete
38 exact_match
// the input matches and is complete
41 /* Defines which matcher_rv values constitute an error. Should be used with
42 * matcher_rv return values to do basic error checking.
44 #define MATCHER_ERROR(matcher_rv) \
45 ((matcher_rv) == MATCHER_INCOMPLETE \
46 || (matcher_rv) == MATCHER_NO_MATCH \
47 || (matcher_rv) == MATCHER_AMBIGUOUS)
50 * Attempt to find an exact command match for a line of user input.
52 * @param[in] cmdgraph command graph to match against
53 * @param[in] vline vectorized input string
54 * @param[out] argv pointer to argument list if successful match, NULL
55 * otherwise. The elements of this list are pointers to struct cmd_token
56 * and represent the sequence of tokens matched by the input. The ->arg
57 * field of each token points to a copy of the input matched on it. These
58 * may be safely deleted or modified.
59 * @param[out] element pointer to matched cmd_element if successful match,
60 * or NULL when MATCHER_ERROR(rv) is true. The cmd_element may *not* be
61 * safely deleted or modified; it is the instance initialized on startup.
62 * @return matcher status
64 enum matcher_rv
command_match(struct graph
*cmdgraph
, vector vline
,
66 const struct cmd_element
**element
);
69 * Compiles possible completions for a given line of user input.
71 * @param[in] start the start node of the DFA to match against
72 * @param[in] vline vectorized input string
73 * @param[out] completions pointer to list of cmd_token representing
74 * acceptable next inputs, or NULL when MATCHER_ERROR(rv) is true.
75 * The elements of this list are pointers to struct cmd_token and take on a
76 * variety of forms depending on the passed vline. If the last element in vline
77 * is NULL, all previous elements are considered to be complete words (the case
78 * when a space is the last token of the line) and completions are generated
79 * based on what could follow that input. If the last element in vline is not
80 * NULL and each sequential element matches the corresponding tokens of one or
81 * more commands exactly (e.g. 'encapv4' and not 'en') the same result is
82 * generated. If the last element is not NULL and the best possible match is a
83 * partial match, then the result generated will be all possible continuations
84 * of that element (e.g. 'encapv4', 'encapv6', etc for input 'en').
85 * @return matcher status
87 enum matcher_rv
command_complete(struct graph
*cmdgraph
, vector vline
,
88 struct list
**completions
);
94 #endif /* _ZEBRA_COMMAND_MATCH_H */