2 * Copyright 2018-2021 NXP.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
39 extern const char * g_vt_boldwhite
;
40 extern const char * g_vt_default
;
41 extern const char * g_vt_kcyn
;
42 extern const char * g_vt_green
;
43 extern const char * g_vt_red
;
44 extern const char * g_vt_yellow
;
47 * @brief Structure to hold the raw data of a built-in script
49 struct BuiltInScriptRawData
51 //! The name of the built-in script
52 const char *m_name
= nullptr;
53 //! The actual built-in script itself
54 const char *m_text
= nullptr;
55 //! A description of the built-in script's purpose
56 const char *m_desc
= nullptr;
63 * @brief A class for representing arguments of built-in scripts represented
76 Arg() { m_flags
= ARG_MUST
; }
78 int parser(const std::string
&option
);
80 //! The name of the argument
82 //! A description of the argument
84 //! Flags of the argument (basically if it's optional or not)
86 //! The argument whose value this one will fall back to if it's optional
87 //! and not given explicitly
88 std::string m_fallback_option
;
92 BuiltInScript(const BuiltInScriptRawData
*p
);
94 std::string
replace_script_args(const std::vector
<std::string
> &args
) const;
96 void show_cmd() const;
98 //! The actual script which is being represented
100 //! A description of the script's purpose
102 //! A short name of the built-in script
104 //! The arguments of the built-in script
105 std::vector
<Arg
> m_args
;
108 bool find_args(const std::string
&arg
) const;
112 * @brief A map of all built-in scripts indexed by their names
114 * Each built-in script is represented by a BuiltInScript instance.
116 class BuiltInScriptMap
: public std::map
<std::string
, BuiltInScript
>
119 BuiltInScriptMap(const BuiltInScriptRawData
*p
);
121 void PrintAutoComplete(std::string match
, const char *space
=" " ) const;
122 void ShowAll() const;
123 void ShowCmds(FILE * file
=stdout
) const;
126 //! A map of the built-in scripts' names to their BuiltInScript representations
127 extern BuiltInScriptMap g_BuildScripts
;