1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief a header file with common samples functionality
7 * @file args_helper.hpp
14 #include <gflags/gflags.h>
19 #include <os/windows/w_dirent.h>
25 * @brief This function checks input args and existence of specified files in a given folder
26 * @param arg path to a file to be checked for existence
27 * @return files updated vector of verified input files
29 void readInputFilesArguments(std::vector<std::string> &files, const std::string& arg) {
31 if (stat(arg.c_str(), &sb) != 0) {
32 slog::warn << "File " << arg << " cannot be opened!" << slog::endl;
35 if (S_ISDIR(sb.st_mode)) {
37 dp = opendir(arg.c_str());
39 slog::warn << "Directory " << arg << " cannot be opened!" << slog::endl;
44 while (nullptr != (ep = readdir(dp))) {
45 std::string fileName = ep->d_name;
46 if (fileName == "." || fileName == "..") continue;
47 files.push_back(arg + "/" + ep->d_name);
54 if (files.size() < 20) {
55 slog::info << "Files were added: " << files.size() << slog::endl;
56 for (std::string filePath : files) {
57 slog::info << " " << filePath << slog::endl;
60 slog::info << "Files were added: " << files.size() << ". Too many to display each of them." << slog::endl;
65 * @brief This function find -i/--images key in input args
66 * It's necessary to process multiple values for single key
67 * @return files updated vector of verified input files
69 void parseInputFilesArguments(std::vector<std::string> &files) {
70 std::vector<std::string> args = gflags::GetArgvs();
71 bool readArguments = false;
72 for (size_t i = 0; i < args.size(); i++) {
73 if (args.at(i) == "-i" || args.at(i) == "--images") {
80 if (args.at(i).c_str()[0] == '-') {
83 readInputFilesArguments(files, args.at(i));