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