• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 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 "options.h"
17 
18 #include <sstream>
19 
20 namespace panda::proto {
21 // Options
Options()22 Options::Options() : argparser_(new panda::PandArgParser()) {}
23 
~Options()24 Options::~Options()
25 {
26     delete argparser_;
27 }
28 
Parse(int argc,const char ** argv)29 bool Options::Parse(int argc, const char **argv)
30 {
31     panda::PandArg<bool> opHelp("help", false, "Print this message and exit");
32 
33     panda::PandArg<std::string> protoPathInput("input", "",
34                                                "Path of Proto bin file or directory. If input path starts with '@', "
35                                                "it considered as a text file with list of files or directories.");
36     panda::PandArg<std::string> protoBinSuffix("suffix", "", "suffix of proto bin file");
37     panda::PandArg<std::string> outputFileName("output", "", "name of merged panda file");
38     panda::PandArg<std::string> outputFilePath("outputFilePath", "", "output path for merged panda file");
39 
40     argparser_->Add(&opHelp);
41     argparser_->Add(&protoPathInput);
42     argparser_->Add(&protoBinSuffix);
43     argparser_->Add(&outputFileName);
44     argparser_->Add(&outputFilePath);
45 
46     if (!argparser_->Parse(argc, argv) || opHelp.GetValue() || protoPathInput.GetValue().empty()) {
47         std::stringstream ss;
48 
49         ss << argparser_->GetErrorString() << std::endl;
50         ss << "Usage: "
51            << "merge_abc"
52            << " [OPTIONS] --input" << std::endl;
53         ss << std::endl;
54         ss << "optional arguments:" << std::endl;
55         ss << argparser_->GetHelpString() << std::endl;
56 
57         errorMsg_ = ss.str();
58         return false;
59     }
60 
61     protoPathInput_ = protoPathInput.GetValue();
62     if (!protoBinSuffix.GetValue().empty()) {
63         protoBinSuffix_ = protoBinSuffix.GetValue();
64     }
65     if (!outputFileName.GetValue().empty()) {
66         outputFileName_ = outputFileName.GetValue();
67     }
68     if (!outputFilePath.GetValue().empty()) {
69         outputFilePath_ = outputFilePath.GetValue();
70     }
71 
72     return true;
73 }
74 }
75