diff --git a/CHANGELOG.md b/CHANGELOG.md index 1534e4a0..f0ec5981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # CHANGELOG + * Fixed add_compile_flags and added remove_compile_flags config options (#130) * Added rendering of template specialization fields and methods (#128) * Improved template specialization/instantiation matching based on deduced context diff --git a/src/cli/cli_handler.cc b/src/cli/cli_handler.cc index b6c10240..08220881 100644 --- a/src/cli/cli_handler.cc +++ b/src/cli/cli_handler.cc @@ -83,6 +83,11 @@ cli_flow_t cli_handler::parse(int argc, const char **argv) app.add_flag("-l,--list-diagrams", list_diagrams, "Print list of diagrams defined in the config file"); app.add_flag("--init", initialize, "Initialize example config file"); + app.add_option("--add-compile-flag", add_compile_flag, + "Add a compilation flag to each entry in the compilation database"); + app.add_option("--remove-compile-flag", remove_compile_flag, + "Remove a compilation flag from each entry in the compilation " + "database"); app.add_option( "--add-class-diagram", add_class_diagram, "Add class diagram config"); app.add_option("--add-sequence-diagram", add_sequence_diagram, @@ -269,6 +274,21 @@ cli_flow_t cli_handler::handle_post_config_options() if (!ensure_output_directory_exists(effective_output_directory)) return cli_flow_t::kError; + // + // Append add_compile_flags and remove_compile_flags to the config + // + if (add_compile_flag) { + std::copy(add_compile_flag->begin(), add_compile_flag->end(), + std::back_inserter(config.add_compile_flags.value)); + config.add_compile_flags.has_value = true; + } + + if (remove_compile_flag) { + std::copy(remove_compile_flag->begin(), remove_compile_flag->end(), + std::back_inserter(config.remove_compile_flags.value)); + config.remove_compile_flags.has_value = true; + } + return cli_flow_t::kContinue; } diff --git a/src/cli/cli_handler.h b/src/cli/cli_handler.h index 575a113c..a2dce4d1 100644 --- a/src/cli/cli_handler.h +++ b/src/cli/cli_handler.h @@ -121,6 +121,8 @@ public: bool list_diagrams{false}; bool quiet{false}; bool initialize{false}; + std::optional> add_compile_flag; + std::optional> remove_compile_flag; std::optional add_class_diagram; std::optional add_sequence_diagram; std::optional add_package_diagram; diff --git a/tests/test_cli_handler.cc b/tests/test_cli_handler.cc index 799b1d38..b64947a0 100644 --- a/tests/test_cli_handler.cc +++ b/tests/test_cli_handler.cc @@ -156,4 +156,31 @@ TEST_CASE("Test cli handler print_diagram_template", "[unit-test]") namespaces: [{{ namespace_name }}] )"); +} + +TEST_CASE( + "Test cli handler add_compile_flag and remove_compile_flag", "[unit-test]") +{ + using clanguml::cli::cli_flow_t; + using clanguml::cli::cli_handler; + using clanguml::util::contains; + + std::vector argv{"clang-uml", "--config", + "./test_config_data/simple.yml", "--add-compile-flag", "-Wno-error", + "--add-compile-flag", "-Wno-warning", "--remove-compile-flag", + "-I/usr/include"}; + + std::ostringstream ostr; + cli_handler cli{ostr, make_sstream_logger(ostr)}; + + auto res = cli.handle_options(argv.size(), argv.data()); + + REQUIRE(res == cli_flow_t::kContinue); + + REQUIRE(cli.config.add_compile_flags.has_value); + REQUIRE(cli.config.remove_compile_flags.has_value); + + REQUIRE(contains(cli.config.add_compile_flags(), "-Wno-error")); + REQUIRE(contains(cli.config.add_compile_flags(), "-Wno-warning")); + REQUIRE(contains(cli.config.remove_compile_flags(), "-I/usr/include")); } \ No newline at end of file