• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 #include "CommandParser.h"
17 
18 #include <algorithm>
19 #include <cstdlib>
20 #include <regex>
21 #include "FileSystem.h"
22 #include "PreviewerEngineLog.h"
23 #include "TraceTool.h"
24 
25 using namespace std;
26 CommandParser* CommandParser::example = nullptr;
CommandParser()27 CommandParser::CommandParser()
28     : isSendJSHeap(true),
29       orignalResolutionWidth(0),
30       orignalResolutionHeight(0),
31       compressionResolutionWidth(0),
32       compressionResolutionHeight(0),
33       jsHeapSize(MAX_JSHEAPSIZE),
34       deviceType("liteWearable"),
35       screenShape("circle"),
36       appName("undefined"),
37       configPath(""),
38       isRegionRefresh(false),
39       isCardDisplay(false),
40       projectID(""),
41       screenMode(CommandParser::ScreenMode::DYNAMIC),
42       configChanges(""),
43       appResourcePath(""),
44       projectModel("FA"),
45       pages("main_pages"),
46       containerSdkPath("")
47 {
48     Register("-j", 1, "Launch the js app in <directory>.");
49     Register("-n", 1, "Set the js app name show on <window title>.");
50     Register("-d", 0, "Run in debug mode and start debug server.");
51     Register("-p", 1, "Config debug server to listen <port>.");
52     Register("-s", 1, "Local socket name <socket-name> for command line interface.");
53     Register("-v", 0, "Print the periviewer engine version.");
54     Register("-h", 0, "Print the usage help.");
55     Register("-or", 2, "Original resolution <width> <height>"); // 2 arguments
56     Register("-cr", 2, "Compression resolution <width> <height>"); // 2 arguments
57     Register("-f", 1, "config path <path>");
58     Register("-hs", 1, "JS Heap <size>");
59     Register("-hf", 1, "JS Send Heap <flag>");
60     Register("-shape", 1, "Screen shape <shape>");
61     Register("-device", 1, "Device type <type>");
62     Register("-url", 1, "temp url");
63     Register("-refresh", 1, "Screen <refresh mode>, support region and full");
64     Register("-card", 1, "Controls the display <type> to switch between the app and card.");
65     Register("-projectID", 1, "the ID of current project.");
66     Register("-ts", 1, "Trace socket name");
67     Register("-cm", 1, "Set colormode for the theme.");
68     Register("-o", 1, "Set orientation for the display.");
69     Register("-lws", 1, "Listening port of WebSocket");
70     Register("-av", 1, "Set ace version.");
71     Register("-l", 1, "Set language for startParam.");
72     Register("-sd", 1, "Set screenDensity for Previewer.");
73     Register("-sm", 1, "Set Screen picture transport mode, support dynamic and static");
74     Register("-cc", 1, "Set Resource configChanges.");
75     Register("-arp", 1, "Set App ResourcePath.");
76     Register("-fs", 1, "Select Fonts sources.");
77     Register("-pm", 1, "Set project model type.");
78     Register("-pages", 1, "Set project's router config file path.");
79     Register("-hsp", 1, "Set container sdk path.");
80     Register("-cpm", 1, "Set previewer start mode.");
81 }
82 
GetInstance()83 CommandParser& CommandParser::GetInstance()
84 {
85     static CommandParser instance;
86     return instance;
87 }
88 
89 /*
90  * Parse user input and check parameter validity
91  */
ProcessCommand(std::vector<std::string> strs)92 bool CommandParser::ProcessCommand(std::vector<std::string> strs)
93 {
94     ProcessingCommand(strs);
95 
96     if (IsSet("v")) {
97         ELOG("ProcessCommand Set -v!");
98         return false;
99     }
100 
101     if (IsSet("h")) {
102         ELOG("ProcessCommand Set -h!");
103         ELOG(HelpText().c_str());
104         return false;
105     }
106 
107     return true;
108 }
109 
IsCommandValid()110 bool CommandParser::IsCommandValid()
111 {
112     bool partRet = IsDebugPortValid() && IsAppPathValid() && IsAppNameValid() && IsResolutionValid();
113     partRet = partRet && IsConfigPathValid() && IsJsHeapValid() && IsJsHeapFlagValid() && IsScreenShapeValid();
114     partRet = partRet && IsDeviceValid() && IsUrlValid() && IsRefreshValid() && IsCardValid() && IsProjectIDValid();
115     partRet = partRet && IsColorModeValid() && IsOrientationValid() && IsWebSocketPortValid() && IsAceVersionValid();
116     partRet = partRet && IsScreenModeValid() && IsAppResourcePathValid();
117     partRet = partRet && IsProjectModelValid() && IsPagesValid() && IsContainerSdkPathValid();
118     partRet = partRet && IsComponentModeValid();
119     if (partRet) {
120         return true;
121     }
122     ELOG(errorInfo.c_str());
123     ILOG(HelpText().c_str());
124     TraceTool::GetInstance().HandleTrace("Invalid startup parameters");
125     return false;
126 }
127 
IsSet(string key)128 bool CommandParser::IsSet(string key)
129 {
130     if (argsMap.find(string("-") + key) == argsMap.end()) {
131         return false;
132     }
133     return true;
134 }
135 
Value(string key)136 string CommandParser::Value(string key)
137 {
138     auto args = argsMap[string("-") + key];
139     if (args.size() > 0) {
140         return args[0];
141     }
142     return string();
143 }
144 
Values(string key)145 vector<string> CommandParser::Values(string key)
146 {
147     if (argsMap.find(key) == argsMap.end()) {
148         return vector<string>();
149     }
150     vector<string> args = argsMap[key];
151     return args;
152 }
153 
Register(string key,uint32_t argc,string help)154 void CommandParser::Register(string key, uint32_t argc, string help)
155 {
156     regsArgsCountMap[key] = argc;
157     regsHelpMap[key] = help;
158 }
159 
IsResolutionValid(int32_t resolution) const160 bool CommandParser::IsResolutionValid(int32_t resolution) const
161 {
162     if (resolution >= MIN_RESOLUTION && resolution <= MAX_RESOLUTION) {
163         return true;
164     }
165     return false;
166 }
167 
GetDeviceType() const168 string CommandParser::GetDeviceType() const
169 {
170     return deviceType;
171 }
172 
IsRegionRefresh() const173 bool CommandParser::IsRegionRefresh() const
174 {
175     return isRegionRefresh;
176 }
177 
IsCardDisplay() const178 bool CommandParser::IsCardDisplay() const
179 {
180     return isCardDisplay;
181 }
182 
GetConfigPath() const183 string CommandParser::GetConfigPath() const
184 {
185     return configPath;
186 }
187 
GetProjectID() const188 string CommandParser::GetProjectID() const
189 {
190     return projectID;
191 }
192 
GetAppResourcePath() const193 string CommandParser::GetAppResourcePath() const
194 {
195     return appResourcePath;
196 }
197 
GetScreenShape() const198 string CommandParser::GetScreenShape() const
199 {
200     return screenShape;
201 }
202 
GetProjectModel() const203 string CommandParser::GetProjectModel() const
204 {
205     return projectModel;
206 }
207 
GetPages() const208 string CommandParser::GetPages() const
209 {
210     return pages;
211 }
212 
GetContainerSdkPath() const213 string CommandParser::GetContainerSdkPath() const
214 {
215     return containerSdkPath;
216 }
217 
GetScreenMode() const218 CommandParser::ScreenMode CommandParser::GetScreenMode() const
219 {
220     return screenMode;
221 }
222 
GetConfigChanges() const223 string CommandParser::GetConfigChanges() const
224 {
225     return configChanges;
226 }
227 
GetOrignalResolutionWidth() const228 int32_t CommandParser::GetOrignalResolutionWidth() const
229 {
230     return orignalResolutionWidth;
231 }
232 
GetOrignalResolutionHeight() const233 int32_t CommandParser::GetOrignalResolutionHeight() const
234 {
235     return orignalResolutionHeight;
236 }
237 
GetCompressionResolutionWidth() const238 int32_t CommandParser::GetCompressionResolutionWidth() const
239 {
240     return compressionResolutionWidth;
241 }
242 
GetCompressionResolutionHeight() const243 int32_t CommandParser::GetCompressionResolutionHeight() const
244 {
245     return compressionResolutionHeight;
246 }
247 
GetJsHeapSize() const248 uint32_t CommandParser::GetJsHeapSize() const
249 {
250     return jsHeapSize;
251 }
252 
GetAppName() const253 string CommandParser::GetAppName() const
254 {
255     return appName;
256 }
257 
IsSendJSHeap() const258 bool CommandParser::IsSendJSHeap() const
259 {
260     return isSendJSHeap;
261 }
262 
IsComponentMode() const263 bool CommandParser::IsComponentMode() const
264 {
265     return isComponentMode;
266 }
267 
IsDebugPortValid()268 bool CommandParser::IsDebugPortValid()
269 {
270     if (IsSet("p")) {
271         if (CheckParamInvalidity(Value("p"), true)) {
272             errorInfo = "Launch -p parameters is not match regex.";
273             return false;
274         }
275         int port = atoi(Value("p").c_str());
276         if (port < MIN_PORT || port > MAX_PORT) {
277             errorInfo =
278                 string("Debug server port out of range: " + to_string(MIN_PORT) + "-" + to_string(MAX_PORT) + ".");
279             ELOG("Launch -p parameters abnormal!");
280             return false;
281         }
282     }
283     ILOG("CommandParser debug port: %s", Value("p").c_str());
284     return true;
285 }
286 
IsAppPathValid()287 bool CommandParser::IsAppPathValid()
288 {
289     if (!IsSet("j")) {
290         errorInfo = string("No app path specified.");
291         ELOG("Launch -j parameters abnormal!");
292         return false;
293     }
294     string path = Value("j");
295     if (!FileSystem::IsDirectoryExists(path)) {
296         errorInfo = string("Js app path not exist.");
297         ELOG("Launch -j parameters abnormal!");
298         return false;
299     }
300 
301     return true;
302 }
303 
IsAppNameValid()304 bool CommandParser::IsAppNameValid()
305 {
306     if (IsSet("n")) {
307         if (CheckParamInvalidity(Value("n"), false)) {
308             errorInfo = "Launch -n parameters is not match regex.";
309             return false;
310         }
311         size_t size = Value("n").size();
312         if (size > MAX_NAME_LENGTH) {
313             errorInfo = string("Js app name it too long, max: " + to_string(MAX_NAME_LENGTH) + ".");
314             return false;
315         }
316         appName = Value("n");
317     }
318     ILOG("CommandParser app name: %s", appName.c_str());
319     return true;
320 }
321 
IsResolutionValid()322 bool CommandParser::IsResolutionValid()
323 {
324     if (IsSet("or") && IsSet("cr")) {
325         if (IsResolutionArgValid(string("-or")) && IsResolutionArgValid(string("-cr"))) {
326             orignalResolutionWidth = atoi(Values("-or")[0].c_str());
327             orignalResolutionHeight = atoi(Values("-or")[1].c_str());
328             compressionResolutionWidth = atoi(Values("-cr")[0].c_str());
329             compressionResolutionHeight = atoi(Values("-cr")[1].c_str());
330             ILOG("CommandParser resolution: %d %d %d %d", orignalResolutionWidth, orignalResolutionHeight,
331                  compressionResolutionWidth, compressionResolutionHeight);
332             return true;
333         }
334         ELOG("Launch -cr/-or parameters abnormal!");
335         return false;
336     }
337     ELOG("Launch -cr/-or parameters abnormal!");
338     errorInfo = string("Origin resolution and compress resolution must be setted.");
339     return false;
340 }
341 
IsJsHeapValid()342 bool CommandParser::IsJsHeapValid()
343 {
344     if (IsSet("hs")) {
345         if (CheckParamInvalidity(Value("hs"), true)) {
346             errorInfo = "Launch -hs parameters is not match regex.";
347             return false;
348         }
349         int size = atoi(Value("hs").c_str());
350         if (size < MIN_JSHEAPSIZE || size > MAX_JSHEAPSIZE) {
351             errorInfo = string("JS heap size out of range: " + to_string(MIN_JSHEAPSIZE) + "-" +
352                                to_string(MAX_JSHEAPSIZE) + ".");
353             ELOG("Launch -hs parameters abnormal!");
354             return false;
355         }
356         jsHeapSize = static_cast<uint32_t>(size);
357     }
358     ILOG("CommandParser js heap: %d", jsHeapSize);
359     return true;
360 }
361 
IsJsHeapFlagValid()362 bool CommandParser::IsJsHeapFlagValid()
363 {
364     if (IsSet("hf")) {
365         string flag = Value("hf");
366         if (flag != "true" && flag != "false") {
367             errorInfo = string("JS heap flag suported: true or false");
368             ELOG("Launch -hs parameters abnormal!");
369             return false;
370         }
371         isSendJSHeap = (flag == "true");
372     }
373     ILOG("CommandParser is send JS heap: %d", isSendJSHeap);
374     return true;
375 }
376 
IsScreenShapeValid()377 bool CommandParser::IsScreenShapeValid()
378 {
379     if (IsSet("shape")) {
380         string shape = Value("shape");
381         if (shape != "rect" && shape != "circle") {
382             errorInfo = string("Screen shape suported: rect or circle");
383             ELOG("The current device does not support, please upgrade the SDK!");
384             return false;
385         }
386         screenShape = shape;
387     }
388     ILOG("CommandParser screen shape: %s", screenShape.c_str());
389     return true;
390 }
391 
IsDeviceValid()392 bool CommandParser::IsDeviceValid()
393 {
394     if (IsSet("device")) {
395         auto iter = find(supportedDevices.begin(), supportedDevices.end(), Value("device"));
396         if (iter == supportedDevices.end()) {
397             errorInfo += string("Device type unsupport, please upgrade the Previewer SDK!");
398             ELOG("Device type unsupport!");
399             return false;
400         }
401     }
402     deviceType = Value("device");
403     ILOG("CommandParser device: %s", deviceType.c_str());
404     return true;
405 }
406 
IsUrlValid()407 bool CommandParser::IsUrlValid()
408 {
409     urlPath = Value("url");
410     if (urlPath.empty()) {
411         errorInfo = "Launch -url parameters is empty.";
412         return false;
413     }
414     ILOG("CommandParser url: %s", urlPath.c_str());
415     return true;
416 }
417 
IsConfigPathValid()418 bool CommandParser::IsConfigPathValid()
419 {
420     if (!IsSet("f")) {
421         return true;
422     }
423 
424     string path = Value("f");
425     if (!FileSystem::IsFileExists(path)) {
426         errorInfo = string("The configuration file path does not exist.");
427         ELOG("Launch -f parameters abnormal!");
428         return false;
429     }
430     configPath = path;
431     return true;
432 }
433 
IsAppResourcePathValid()434 bool CommandParser::IsAppResourcePathValid()
435 {
436     if (!IsSet("arp")) {
437         return true;
438     }
439 
440     string path = Value("arp");
441     if (!FileSystem::IsDirectoryExists(path)) {
442         errorInfo = string("The configuration appResource path does not exist.");
443         ELOG("Launch -arp parameters abnormal!");
444         return false;
445     }
446     appResourcePath = path;
447     return true;
448 }
449 
IsProjectModelValid()450 bool CommandParser::IsProjectModelValid()
451 {
452     if (!IsSet("pm")) {
453         return true;
454     }
455 
456     string projectModelStr = Value("pm");
457     auto iter = find(projectModels.begin(), projectModels.end(), projectModelStr);
458     if (iter == projectModels.end()) {
459         errorInfo = string("The project model does not exist.");
460         ELOG("Launch -pm parameters abnormal!");
461         return false;
462     }
463 
464     projectModel = projectModelStr;
465     ILOG("CommandParser projectModel: %s", projectModelStr.c_str());
466     return true;
467 }
468 
IsPagesValid()469 bool CommandParser::IsPagesValid()
470 {
471     if (!IsSet("pages")) {
472         return true;
473     }
474     pages = Value("pages");
475     if (CheckParamInvalidity(pages, false)) {
476         errorInfo = "Launch -pages parameters is not match regex.";
477         return false;
478     }
479     ILOG("CommandParser pages: %s", pages.c_str());
480     return true;
481 }
482 
IsResolutionArgValid(string command)483 bool CommandParser::IsResolutionArgValid(string command)
484 {
485     vector<string> value = Values(command);
486     uint32_t size = regsArgsCountMap[command];
487     if (value.size() != size) {
488         errorInfo = string("Invalid argument's count.");
489         return false;
490     }
491     if (IsResolutionRangeValid(value[0]) && IsResolutionRangeValid(value[1])) {
492         return true;
493     }
494     return false;
495 }
496 
IsResolutionRangeValid(string value)497 bool CommandParser::IsResolutionRangeValid(string value)
498 {
499     if (CheckParamInvalidity(value, true)) {
500         errorInfo = "Launch -or/-cr parameters is not match regex.";
501         return false;
502     }
503     int32_t temp = atoi(value.c_str());
504     if (!IsResolutionValid(temp)) {
505         errorInfo = string("Resolution range " + to_string(MIN_RESOLUTION) + "-" + to_string(MAX_RESOLUTION) + ".");
506         return false;
507     }
508     return true;
509 }
510 
IsRefreshValid()511 bool CommandParser::IsRefreshValid()
512 {
513     if (!IsSet("refresh")) {
514         return true;
515     }
516 
517     string refresh = Value("refresh");
518     if (refresh != "region" && refresh != "full") {
519         errorInfo = string("The refresh argument unsupported.");
520         ELOG("Launch -refresh parameters abnormal!");
521         return false;
522     }
523     if (refresh == "region") {
524         isRegionRefresh = true;
525     }
526     return true;
527 }
528 
IsCardValid()529 bool CommandParser::IsCardValid()
530 {
531     if (!IsSet("card")) {
532         return true;
533     }
534 
535     string card = Value("card");
536     if (card != "true" && card != "false") {
537         errorInfo = string("The card argument unsupported.");
538         ELOG("Launch -card parameters abnormal!");
539         return false;
540     }
541 
542     std::string devicetype = GetDeviceType();
543     auto iter = find(cardDisplayDevices.begin(), cardDisplayDevices.end(), devicetype);
544     if (iter != cardDisplayDevices.end() && card == "true") {
545         isCardDisplay = true;
546     }
547     return true;
548 }
549 
IsProjectIDValid()550 bool CommandParser::IsProjectIDValid()
551 {
552     if (IsSet("projectID")) {
553         projectID = Value("projectID");
554         if (CheckParamInvalidity(projectID, true)) {
555             errorInfo = "Launch -projectID parameters is not match regex.";
556             return false;
557         }
558     }
559     return true;
560 }
561 
IsColorModeValid()562 bool CommandParser::IsColorModeValid()
563 {
564     if (!IsSet("cm")) {
565         return true;
566     }
567 
568     string colorMode = Value("cm");
569     if (colorMode != "dark" && colorMode != "light") {
570         errorInfo = string("The colormode argument unsupported.");
571         ELOG("Launch -cm parameters abnormal!");
572         return false;
573     }
574     return true;
575 }
576 
IsAceVersionValid()577 bool CommandParser::IsAceVersionValid()
578 {
579     if (!IsSet("av")) {
580         return true;
581     }
582 
583     string aceVersion = Value("av");
584     if (aceVersion != "ACE_1_0" && aceVersion != "ACE_2_0") {
585         errorInfo = string("The aceVersion argument unsupported.");
586         ELOG("Launch -av parameters abnormal!");
587         return false;
588     }
589     return true;
590 }
591 
IsOrientationValid()592 bool CommandParser::IsOrientationValid()
593 {
594     if (!IsSet("o")) {
595         return true;
596     }
597 
598     string orientation = Value("o");
599     if (orientation != "portrait" && orientation != "landscape") {
600         errorInfo = string("The orientation argument unsupported.");
601         ELOG("Launch -o parameters abnormal!");
602         return false;
603     }
604     return true;
605 }
606 
IsWebSocketPortValid()607 bool CommandParser::IsWebSocketPortValid()
608 {
609     if (IsSet("lws")) {
610         if (CheckParamInvalidity(Value("lws"), true)) {
611             errorInfo = "Launch -lws parameters is not match regex.";
612             return false;
613         }
614         int port = atoi(Value("lws").c_str());
615         if (port < MIN_PORT || port > MAX_PORT) {
616             errorInfo = string("WebSocket listening port out of range: " + to_string(MIN_PORT) + "-" +
617                                to_string(MAX_PORT) + ".");
618             ELOG("Launch -lws parameters abnormal!");
619             return false;
620         }
621     }
622     ILOG("CommandParser WebSocket listening port: %s", Value("lws").c_str());
623     return true;
624 }
625 
IsScreenModeValid()626 bool CommandParser::IsScreenModeValid()
627 {
628     string mode("dynamic");
629     if (IsSet("sm")) {
630         mode = Value("sm");
631         if (mode != "dynamic" && mode != "static") {
632             errorInfo = string("Screen picture transport mode suported: dynamic or static");
633             ELOG("Launch -sm parameters abnormal!");
634             return false;
635         }
636         screenMode = (mode == "static" ? CommandParser::ScreenMode::STATIC :
637                       CommandParser::ScreenMode::DYNAMIC);
638     }
639     ILOG("CommandParser screen mode: %s", mode.c_str());
640     return true;
641 }
642 
IsLanguageValid()643 bool CommandParser::IsLanguageValid()
644 {
645     if (!IsSet("l")) {
646         return true;
647     }
648     string lan = Value("pages");
649     if (CheckParamInvalidity(lan, false)) {
650         errorInfo = "Launch -l parameters is not match regex.";
651         return false;
652     }
653     ILOG("CommandParser l: %s", lan.c_str());
654     return true;
655 }
656 
IsTracePipeNameValid()657 bool CommandParser::IsTracePipeNameValid()
658 {
659     if (!IsSet("ts")) {
660         return true;
661     }
662     string tsName = Value("ts");
663     if (CheckParamInvalidity(tsName, false)) {
664         errorInfo = "Launch -ts parameters is not match regex.";
665         return false;
666     }
667     ILOG("CommandParser ts: %s", tsName.c_str());
668     return true;
669 }
670 
IsLocalSocketNameValid()671 bool CommandParser::IsLocalSocketNameValid()
672 {
673     if (!IsSet("s")) {
674         return true;
675     }
676     string socketName = Value("s");
677     if (CheckParamInvalidity(socketName, false)) {
678         errorInfo = "Launch -s parameters is not match regex.";
679         return false;
680     }
681     ILOG("CommandParser s: %s", socketName.c_str());
682     return true;
683 }
684 
IsConfigChangesValid()685 bool CommandParser::IsConfigChangesValid()
686 {
687     if (!IsSet("cc")) {
688         return true;
689     }
690     string configChange = Value("cc");
691     if (CheckParamInvalidity(configChange, false)) {
692         ELOG("Launch -cc parameters is not match regex.");
693         return false;
694     }
695     ILOG("CommandParser cc: %s", configChange.c_str());
696     return true;
697 }
698 
IsScreenDensityValid()699 bool CommandParser::IsScreenDensityValid()
700 {
701     if (!IsSet("sd")) {
702         return true;
703     }
704     string density = Value("sd");
705     if (CheckParamInvalidity(density, true)) {
706         errorInfo = "Launch -sd parameters is not match regex.";
707         return false;
708     }
709     ILOG("CommandParser sd: %s", density.c_str());
710     return true;
711 }
712 
IsContainerSdkPathValid()713 bool CommandParser::IsContainerSdkPathValid()
714 {
715     if (!IsSet("hsp")) {
716         return true;
717     }
718 
719     string path = Value("hsp");
720     if (!FileSystem::IsDirectoryExists(path)) {
721         errorInfo = string("The container sdk path does not exist.");
722         ELOG("Launch -hsp parameters abnormal!");
723         return false;
724     }
725     containerSdkPath = path;
726     return true;
727 }
728 
HelpText()729 string CommandParser::HelpText()
730 {
731     string helpText = "Usage:\n";
732     for (auto index = regsHelpMap.begin(); index != regsHelpMap.end(); index++) {
733         helpText += "-" + index->first + " ";
734         helpText += index->second + "\n";
735     }
736     return helpText;
737 }
738 
ProcessingCommand(const std::vector<string> & strs)739 void CommandParser::ProcessingCommand(const std::vector<string>& strs)
740 {
741     for (unsigned int i = 0; i < strs.size(); ++i) {
742         string index = strs[i];
743         auto regInfo = regsArgsCountMap.find(strs[i]);
744         if (regInfo == regsArgsCountMap.end()) {
745             continue;
746         }
747 
748         vector<string> args;
749         for (uint32_t j = 0; j < regInfo->second; ++j) {
750             if (i == strs.size() - 1  || strs[i + 1][0] == '-') {
751                 args.push_back("");
752                 break;
753             }
754             args.push_back(strs[++i]);
755         }
756         argsMap[index] = args;
757     }
758 }
759 
GetProjectModelEnumValue() const760 int CommandParser::GetProjectModelEnumValue() const
761 {
762     auto idxVal = std::distance(projectModels.begin(),
763                                 find(projectModels.begin(), projectModels.end(), projectModel));
764     idxVal = (idxVal >= projectModels.size()) ? 0 : idxVal;
765     return idxVal;
766 }
767 
GetProjectModelEnumName(int enumValue) const768 string CommandParser::GetProjectModelEnumName(int enumValue) const
769 {
770     if (enumValue < 0 || enumValue >= projectModels.size()) {
771         enumValue = 0;
772     }
773     return projectModels[enumValue];
774 }
775 
CheckParamInvalidity(string param,bool isNum=false)776 bool CommandParser::CheckParamInvalidity(string param, bool isNum = false)
777 {
778     regex reg(isNum ? regex4Num : regex4Str);
779     return !regex_match(param.cbegin(), param.cend(), reg);
780 }
781 
IsComponentModeValid()782 bool CommandParser::IsComponentModeValid()
783 {
784     if (!IsSet("cpm")) {
785         return true;
786     }
787 
788     string cpm = Value("cpm");
789     if (cpm != "true" && cpm != "false") {
790         errorInfo = string("The component mode argument unsupported.");
791         ELOG("Launch -cpm parameters abnormal!");
792         return false;
793     }
794 
795     isComponentMode = cpm == "true" ? true : false;
796     return true;
797 }