2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-11-02 01:03:15 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
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-03-14 04:51:04 +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-03-14 04:51:04 +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
|
|
|
|
|
|
|
if(it == all.end())
|
2015-11-02 01:03:15 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
|
|
|
|
}
|