summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--icespider/compile/main.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/icespider/compile/main.cpp b/icespider/compile/main.cpp
index 5796bae..b8eb26e 100644
--- a/icespider/compile/main.cpp
+++ b/icespider/compile/main.cpp
@@ -1,7 +1,28 @@
#include "routeCompiler.h"
+#include <boost/algorithm/string/split.hpp>
#include <boost/program_options.hpp>
+#include <compileTimeFormatter.h>
namespace po = boost::program_options;
+using namespace AdHoc::literals;
+
+static std::string
+defaultPostProcessor()
+{
+ constexpr std::array<const std::pair<std::string_view, std::string_view>, 1> pps {{
+ {"clang-format", "-i"},
+ }};
+ const std::string_view path {getenv("PATH")};
+ const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal()));
+ for (const auto & [cmd, opts] : pps) {
+ for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) {
+ if (std::filesystem::exists(std::filesystem::path(p->begin(), p->end()) / cmd)) {
+ return "%? %?"_fmt(cmd, opts);
+ }
+ }
+ }
+ return "";
+}
int
main(int c, char ** v)
@@ -9,12 +30,14 @@ main(int c, char ** v)
bool showHelp;
IceSpider::Compile::RouteCompiler rc;
std::filesystem::path input, output;
+ std::string post;
po::options_description opts("IceSpider compile options");
// clang-format off
opts.add_options()
("input", po::value(&input), "Input .json file")
("output", po::value(&output), "Output .cpp file")
("include,I", po::value(&rc.searchPath)->composing(), "Search path")
+ ("post,p", po::value(&post)->default_value(defaultPostProcessor()), "Post-process command")
("help,h", po::value(&showHelp)->default_value(false)->zero_tokens(), "Help")
;
// clang-format on
@@ -34,5 +57,10 @@ main(int c, char ** v)
rc.searchPath.push_back(input.parent_path());
rc.compile(input, output);
+ if (!post.empty()) {
+ auto outputh = std::filesystem::path(output).replace_extension(".h");
+ return system("%? %? %?"_fmt(post, output, outputh).c_str());
+ }
+
return 0;
}