2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-11-02 01:03:15 +08:00
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
#include <algorithm>
|
2015-11-02 01:03:15 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-08-23 02:03:45 +08:00
|
|
|
#include "utils/option.hpp"
|
2015-11-02 01:03:15 +08:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wunused-function"
|
|
|
|
|
2016-03-14 04:51:04 +08:00
|
|
|
auto all_arguments(int argc, char *argv[])
|
2015-11-02 01:03:15 +08:00
|
|
|
{
|
2016-03-14 04:51:04 +08:00
|
|
|
return std::vector<std::string>(argv + 1, argv + argc);
|
2015-11-02 01:03:15 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
bool contains_argument(const std::vector<std::string> &all,
|
|
|
|
const std::string &flag)
|
2016-01-17 01:24:35 +08:00
|
|
|
{
|
2016-03-14 04:51:04 +08:00
|
|
|
return std::find(all.begin(), all.end(), flag) != all.end();
|
2016-01-17 01:24:35 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
auto get_argument(const std::vector<std::string> &all, const std::string &flag,
|
|
|
|
const std::string &default_value)
|
2015-11-02 01:03:15 +08:00
|
|
|
{
|
|
|
|
auto it = std::find(all.begin(), all.end(), flag);
|
2016-03-14 04:51:04 +08:00
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
if (it == all.end()) return default_value;
|
2016-03-14 04:51:04 +08:00
|
|
|
|
|
|
|
return all[std::distance(all.begin(), it) + 1];
|
2015-11-02 01:03:15 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
Option<std::string> take_argument(std::vector<std::string> &all,
|
|
|
|
const std::string &flag)
|
|
|
|
{
|
|
|
|
auto it = std::find(all.begin(), all.end(), flag);
|
2015-11-02 01:03:15 +08:00
|
|
|
|
2016-08-23 02:03:45 +08:00
|
|
|
if (it == all.end()) return make_option<std::string>();
|
|
|
|
|
|
|
|
auto s = std::string(all[std::distance(all.begin(), it) + 1]);
|
|
|
|
it++;
|
|
|
|
it++;
|
|
|
|
all.erase(std::find(all.begin(), all.end(), flag), it);
|
|
|
|
|
|
|
|
return make_option<std::string>(std::move(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma clang diagnostic pop
|
2015-11-02 01:03:15 +08:00
|
|
|
}
|