uuu
uuu (Universal Update Utility), mfgtools 3.0
Loading...
Searching...
No Matches
buildincmd.h
Go to the documentation of this file.
1/*
2* Copyright 2018-2021 NXP.
3*
4* Redistribution and use in source and binary forms, with or without modification,
5* are permitted provided that the following conditions are met:
6*
7* Redistributions of source code must retain the above copyright notice, this
8* list of conditions and the following disclaimer.
9*
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.
13*
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.
17*
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.
29*
30*/
31
32#pragma once
33
34#include <cstdint>
35#include <map>
36#include <string>
37#include <vector>
38
39extern const char * g_vt_boldwhite;
40extern const char * g_vt_default;
41extern const char * g_vt_kcyn;
42extern const char * g_vt_green;
43extern const char * g_vt_red ;
44extern const char * g_vt_yellow;
45
50{
52 const char * const m_name = nullptr;
54 const char * const m_text = nullptr;
56 const char * const m_desc = nullptr;
57};
58
60{
61public:
66 class Arg
67 {
68 public:
69 enum
70 {
71 ARG_MUST = 0x1,
74 };
75
76 void parser(const std::string &option);
77
79 std::string m_name;
81 std::string m_desc;
83 uint32_t m_flags = ARG_MUST;
86 std::string m_fallback_option;
87 };
88
91
92 std::string replace_script_args(const std::vector<std::string> &args) const;
93 void show() const;
94 void show_cmd() const;
95
97 const std::string m_text;
99 const std::string m_desc;
101 const std::string m_name;
103 std::vector<Arg> m_args;
104
105private:
106 bool find_args(const std::string &arg) const;
107};
108
114class BuiltInScriptMap : public std::map<std::string, BuiltInScript>
115{
116public:
118
119 void PrintAutoComplete(const std::string &match, const char *space = " ") const;
120 void ShowAll() const;
121 void ShowCmds(FILE * file=stdout) const;
122};
123
BuiltInScriptMap g_BuildScripts(g_builtin_cmd)
A map of the built-in scripts' names to their BuiltInScript representations.
const char * g_vt_kcyn
Definition uuu.cpp:56
const char * g_vt_boldwhite
Definition uuu.cpp:57
const char * g_vt_default
Definition uuu.cpp:53
const char * g_vt_green
Definition uuu.cpp:54
const char * g_vt_yellow
Definition uuu.cpp:52
const char * g_vt_red
Definition uuu.cpp:55
A map of all built-in scripts indexed by their names.
Definition buildincmd.h:115
BuiltInScriptMap(const BuiltInScriptRawData *p)
Create a new map by parsing an array of BuiltInScriptRawData instances.
Definition buildincmd.cpp:185
void ShowCmds(FILE *file=stdout) const
Print the names of all contained scripts to the given stream.
Definition buildincmd.cpp:226
void PrintAutoComplete(const std::string &match, const char *space=" ") const
Auto-complete names of built-in scripts if they match match
Definition buildincmd.cpp:200
void ShowAll() const
Print information about all contained scripts to stdout.
Definition buildincmd.cpp:214
A class for representing arguments of built-in scripts represented by BuiltInScript.
Definition buildincmd.h:67
void parser(const std::string &option)
Parse characters between argument name and its description and check if its an optional one.
Definition buildincmd.cpp:48
std::string m_name
The name of the argument.
Definition buildincmd.h:79
uint32_t m_flags
Flags of the argument (basically if it's optional or not)
Definition buildincmd.h:83
std::string m_desc
A description of the argument.
Definition buildincmd.h:81
std::string m_fallback_option
Definition buildincmd.h:86
@ ARG_OPTION
Definition buildincmd.h:72
@ ARG_OPTION_KEY
Definition buildincmd.h:73
@ ARG_MUST
Definition buildincmd.h:71
const std::string m_text
The actual script which is being represented.
Definition buildincmd.h:97
std::vector< Arg > m_args
The arguments of the built-in script.
Definition buildincmd.h:103
bool find_args(const std::string &arg) const
Check if the BuiltInScript instance has an argument called arg
Definition buildincmd.cpp:113
const std::string m_name
A short name of the built-in script.
Definition buildincmd.h:101
const std::string m_desc
A description of the script's purpose.
Definition buildincmd.h:99
void show_cmd() const
Print the script's name, its description and its arguments to stdout.
Definition buildincmd.cpp:163
std::string replace_script_args(const std::vector< std::string > &args) const
Replace built-in script's arguments by actual values given in args
Definition buildincmd.cpp:126
BuiltInScript()
Definition buildincmd.h:89
void show() const
Print the built-in script to stdout followed by a newline.
Definition buildincmd.cpp:155
Structure to hold the raw data of a built-in script.
Definition buildincmd.h:50
const char *const m_name
The name of the built-in script.
Definition buildincmd.h:52
const char *const m_text
The actual built-in script itself.
Definition buildincmd.h:54
const char *const m_desc
A description of the built-in script's purpose.
Definition buildincmd.h:56