|
31 | 31 | #include <unordered_map> |
32 | 32 | #include <vector> |
33 | 33 |
|
34 | | -#if defined(__GNUC__) && __GNUC__ < 8 |
35 | | -#include <experimental/filesystem> |
36 | | -namespace std { |
37 | | -namespace filesystem = std::experimental::filesystem; |
38 | | -} |
39 | | -#elif defined(_MSC_VER) && _MSVC_LANG < 201703L |
40 | | -#include <filesystem> |
41 | | -namespace std { |
42 | | -namespace filesystem = std::experimental::filesystem; |
43 | | -} // namespace std |
44 | | -#else |
45 | | -#include <filesystem> |
46 | | -#endif |
47 | | - |
48 | 34 | namespace argparse { |
49 | 35 | namespace detail { |
50 | | -static std::string _delimit(const std::string &name) { |
51 | | - return std::string(std::min(name.size(), static_cast<size_t>(2)), '-') |
52 | | - .append(name); |
53 | | -} |
54 | | -static std::string _strip(const std::string &name) { |
55 | | - size_t begin = 0; |
56 | | - begin += name.size() > 0 ? name[0] == '-' : 0u; |
57 | | - begin += name.size() > 3 ? name[1] == '-' : 0u; |
58 | | - return name.substr(begin); |
59 | | -} |
60 | | -static std::string _upper(const std::string &in) { |
61 | | - std::string out(in); |
62 | | - std::transform(out.begin(), out.end(), out.begin(), ::toupper); |
63 | | - return out; |
64 | | -} |
65 | | -static std::string _escape(const std::string &in) { |
66 | | - std::string out(in); |
67 | | - if (in.find(' ') != std::string::npos) |
68 | | - out = std::string("\"").append(out).append("\""); |
69 | | - return out; |
70 | | -} |
71 | | -static bool _not_space(int ch) { return !std::isspace(ch); } |
| 36 | +static inline bool _not_space(int ch) { return !std::isspace(ch); } |
72 | 37 | static inline void _ltrim(std::string &s, bool (*f)(int) = _not_space) { |
73 | 38 | s.erase(s.begin(), std::find_if(s.begin(), s.end(), f)); |
74 | 39 | } |
@@ -262,7 +227,8 @@ class ArgumentParser { |
262 | 227 | std::vector<std::string> _values{}; |
263 | 228 | }; |
264 | 229 |
|
265 | | - ArgumentParser(const std::string &desc) : _desc(desc) {} |
| 230 | + ArgumentParser(const std::string &bin, const std::string &desc) |
| 231 | + : _bin(bin), _desc(desc) {} |
266 | 232 |
|
267 | 233 | Argument &add_argument() { |
268 | 234 | _arguments.push_back({}); |
@@ -354,7 +320,6 @@ class ArgumentParser { |
354 | 320 | if (err) { |
355 | 321 | return err; |
356 | 322 | } |
357 | | - _bin = std::filesystem::path(argv[0]).filename().string(); |
358 | 323 |
|
359 | 324 | // parse |
360 | 325 | std::string current_arg; |
@@ -511,7 +476,6 @@ class ArgumentParser { |
511 | 476 | Result _add_value(const std::string &value, int location) { |
512 | 477 | if (_current >= 0) { |
513 | 478 | Result err; |
514 | | - size_t c = static_cast<size_t>(_current); |
515 | 479 | Argument &a = _arguments[static_cast<size_t>(_current)]; |
516 | 480 | if (a._count >= 0 && static_cast<int>(a._values.size()) >= a._count) { |
517 | 481 | err = _end_argument(); |
@@ -559,8 +523,8 @@ class ArgumentParser { |
559 | 523 |
|
560 | 524 | bool _help_enabled{false}; |
561 | 525 | int _current{-1}; |
562 | | - std::string _desc{}; |
563 | 526 | std::string _bin{}; |
| 527 | + std::string _desc{}; |
564 | 528 | std::vector<Argument> _arguments{}; |
565 | 529 | std::map<int, int> _positional_arguments{}; |
566 | 530 | std::map<std::string, int> _name_map{}; |
|
0 commit comments