Skip to content

Commit 07e771d

Browse files
author
Jesse Laning
committed
remove <filesystem> dependence and unused functions
1 parent 1db0062 commit 07e771d

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

argparse.h

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,9 @@
3131
#include <unordered_map>
3232
#include <vector>
3333

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-
4834
namespace argparse {
4935
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); }
7237
static inline void _ltrim(std::string &s, bool (*f)(int) = _not_space) {
7338
s.erase(s.begin(), std::find_if(s.begin(), s.end(), f));
7439
}
@@ -262,7 +227,8 @@ class ArgumentParser {
262227
std::vector<std::string> _values{};
263228
};
264229

265-
ArgumentParser(const std::string &desc) : _desc(desc) {}
230+
ArgumentParser(const std::string &bin, const std::string &desc)
231+
: _bin(bin), _desc(desc) {}
266232

267233
Argument &add_argument() {
268234
_arguments.push_back({});
@@ -354,7 +320,6 @@ class ArgumentParser {
354320
if (err) {
355321
return err;
356322
}
357-
_bin = std::filesystem::path(argv[0]).filename().string();
358323

359324
// parse
360325
std::string current_arg;
@@ -511,7 +476,6 @@ class ArgumentParser {
511476
Result _add_value(const std::string &value, int location) {
512477
if (_current >= 0) {
513478
Result err;
514-
size_t c = static_cast<size_t>(_current);
515479
Argument &a = _arguments[static_cast<size_t>(_current)];
516480
if (a._count >= 0 && static_cast<int>(a._values.size()) >= a._count) {
517481
err = _end_argument();
@@ -559,8 +523,8 @@ class ArgumentParser {
559523

560524
bool _help_enabled{false};
561525
int _current{-1};
562-
std::string _desc{};
563526
std::string _bin{};
527+
std::string _desc{};
564528
std::vector<Argument> _arguments{};
565529
std::map<int, int> _positional_arguments{};
566530
std::map<std::string, int> _name_map{};

example.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* Author: Jesse Laning
1515
*/
1616

17-
#include "argparse.h"
18-
1917
#include <iostream>
2018
#include <iterator>
2119

20+
#include "argparse.h"
21+
2222
using namespace argparse;
2323

2424
int main(int argc, const char* argv[]) {
25-
ArgumentParser parser("Argument parser example");
25+
ArgumentParser parser("example", "Argument parser example");
2626
parser.add_argument()
2727
.names({"-v", "--verbose"})
2828
.description("verbose level")

tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#include "argparse.h"
2-
31
#include <cmath>
42
#include <functional>
53
#include <iostream>
64
#include <string>
75
#include <unordered_map>
86

7+
#include "argparse.h"
8+
99
using namespace argparse;
1010

1111
struct result {
@@ -26,7 +26,7 @@ struct result {
2626
result name() { \
2727
const char* argv[] = {#name, ##__VA_ARGS__}; \
2828
int argc = sizeof(argv) / sizeof(argv[0]); \
29-
ArgumentParser parser(#name); \
29+
ArgumentParser parser(#name, #name); \
3030
code; \
3131
return {true, 0, "", "", ""}; \
3232
}

0 commit comments

Comments
 (0)