Skip to content

Commit cf02040

Browse files
committed
[WIP] argparse
1 parent 1fd155c commit cf02040

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

include/argparse.hpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
#include <argparse/argparse.hpp>
44
#include <string_view>
55

6-
#include "argparse.hpp"
7-
#include "formatters/formatters_base.hpp"
6+
#include "formatters/progress.hpp"
7+
#include "formatters/tap.hpp"
8+
#include "formatters/verbose.hpp"
9+
810

911
namespace CppSpec {
12+
1013
constexpr std::string file_name(std::string_view path) {
1114
std::string_view file = path;
1215
for (size_t i = 0; i < path.size(); ++i) {
@@ -17,15 +20,9 @@ constexpr std::string file_name(std::string_view path) {
1720
return std::string{file};
1821
}
1922

20-
enum class Formatter {
21-
Progress,
22-
TAP,
23-
Detail
24-
};
25-
2623
struct RuntimeOpts {
2724
bool verbose = false;
28-
Formatter format = Formatter::Progress;
25+
std::unique_ptr<Formatters::BaseFormatter> formatter = nullptr;
2926
};
3027

3128
inline RuntimeOpts parse(int argc, char** argv) {
@@ -55,13 +52,18 @@ inline RuntimeOpts parse(int argc, char** argv) {
5552
opts.verbose = true;
5653
}
5754

58-
auto format_string = program.get<std::string>("--format");
55+
auto format_string = program.get<std::string>("--format");
5956
if (format_string == "p" || format_string == "progress") {
60-
opts.format = Formatter::Progress;
57+
opts.formatter = std::make_unique<Formatters::Progress>();
6158
} else if (format_string == "t" || format_string == "tap") {
62-
opts.format = Formatter::TAP;
59+
opts.formatter = std::make_unique<Formatters::TAP>();
6360
} else if (format_string == "d" || format_string == "detail") {
64-
opts.format = Formatter::Detail;
61+
opts.formatter = std::make_unique<Formatters::Verbose>();
62+
} else {
63+
std::cerr << "Unrecognized format type" << std::endl;
64+
std::exit(-1);
6565
}
66+
67+
return opts;
6668
}
6769
} // namespace CppSpec

include/formatters/verbose.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include <list>
77
#include <string>
88

9+
#include "argparse.hpp"
910
#include "class_description.hpp"
1011
#include "formatters_base.hpp"
1112
#include "it_base.hpp"
1213

13-
1414
namespace CppSpec {
1515
namespace Formatters {
1616

@@ -70,12 +70,12 @@ static Verbose verbose;
7070

7171
} // namespace Formatters
7272

73-
template <typename Formatter = Formatters::Verbose>
74-
inline auto Description::as_main() {
73+
template <typename FormatterType = Formatters::Verbose>
74+
inline auto Description::as_main() {
7575
Description description{*this};
76-
return [=](int argc, char** argv) mutable -> int {
77-
Formatter f{};
78-
return description.run(f) ? EXIT_SUCCESS : EXIT_FAILURE;
76+
return [=](int argc, char **argv) mutable -> int {
77+
auto opts = parse(argc, argv);
78+
return description.run(*opts.formatter) ? EXIT_SUCCESS : EXIT_FAILURE;
7979
};
8080
}
8181
} // namespace CppSpec

include/runner.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
#include <list>
88

9-
#include "formatters/progress.hpp"
10-
#include "formatters/tap.hpp"
11-
#include "formatters/verbose.hpp"
9+
#include "argparse.hpp"
1210

1311
namespace CppSpec {
1412

0 commit comments

Comments
 (0)