#include #include #include #include namespace willowc { int willowc_main(int argc, char **argv) { argparse::ArgumentParser cl("willowc"); cl.set_prefix_chars("-"); cl.set_assign_chars("="); willowc::Compiler compiler; auto &ll = cl.add_mutually_exclusive_group(); ll.add_argument("-Lerror") .help("only emit diagnostics on error (default)") .default_value(true) .implicit_value(true) .action( [&](const auto &) { compiler.setLogLevel(willow::Severity::Error); }); ll.add_argument("-Lwarn") .help("emit warning messages") .default_value(false) .implicit_value(true) .action([&](const auto &) { compiler.setLogLevel(willow::Severity::Warning); }); ll.add_argument("-Linfo") .help("emit remarks") .default_value(false) .implicit_value(true) .action([&](const auto &) { compiler.setLogLevel(willow::Severity::Remark); }); ll.add_argument("-Ldebug") .help("emit all diagnostics") .default_value(false) .implicit_value(true) .action( [&](const auto &) { compiler.setLogLevel(willow::Severity::Debug); }); cl.add_argument("").help("input file path").required().nargs(1); if (argc < 2) { std::cerr << cl; return 1; } try { cl.parse_args(argc, argv); } catch (std::exception &e) { std::println("error: {}", e.what()); } std::string f; try { f = cl.get(""); } catch (std::exception &e) { std::println("error: {}", e.what()); return 1; } if (f == "-") { if (willow::failed(compiler.addStdIn())) return 1; } else if (willow::failed(compiler.addSourceFile(f))) return 1; compiler.run(); return 0; } } // namespace willowc