1 /** 2 * Copyright (c) 2021-2024 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 #ifndef PANDA_TOOLS_SAMPLER_ARGS_PARSER_H 17 #define PANDA_TOOLS_SAMPLER_ARGS_PARSER_H 18 19 #include "tools/sampler/panda_gen_options/generated/aspt_converter_options.h" 20 21 namespace ark::tooling::sampler { 22 23 class ArgsParser { 24 public: Parse(ark::Span<const char * > args)25 bool Parse(ark::Span<const char *> args) 26 { 27 options_.AddOptions(&parser_); 28 29 if (!parser_.Parse(args.Size(), args.Data())) { 30 std::cerr << parser_.GetErrorString(); 31 return false; 32 } 33 34 auto err = options_.Validate(); 35 if (err) { 36 std::cerr << err.value().GetMessage() << std::endl; 37 return false; 38 } 39 40 if (options_.GetInput().empty()) { 41 std::cerr << "[Error] Input file is not set." << std::endl; 42 return false; 43 } 44 45 if (options_.GetOutput().empty()) { 46 std::cerr << "[Error] Output file is not set." << std::endl; 47 return false; 48 } 49 50 if (!ark::os::IsFileExists(options_.GetInput())) { 51 std::cerr << "[Error] File \"" << options_.GetInput() << "\" not found." << std::endl; 52 return false; 53 } 54 55 return true; 56 } 57 GetOptions()58 const Options &GetOptions() const 59 { 60 return options_; 61 } 62 Help()63 void Help() const 64 { 65 std::cerr << "AsptConverter usage: " << std::endl; 66 std::cerr << "${BUILD_DIR}/bin/aspt_converter " 67 << "--input=<input_name.aspt> " 68 << "--output=<output_name.csv> " 69 << "[OPTIONS]" << std::endl; 70 std::cerr << "optional arguments:" << std::endl; 71 std::cerr << parser_.GetHelpString() << std::endl; 72 } 73 74 private: 75 PandArgParser parser_; 76 Options options_ {""}; 77 }; 78 79 } // namespace ark::tooling::sampler 80 81 #endif // PANDA_TOOLS_SAMPLER_ARGS_PARSER_H 82