From 9ccc8ec9dff7e6cb456a2ee7d787209650301842 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Wed, 31 Jan 2024 00:37:54 +0100 Subject: [PATCH] Maybe? --- include/sharg/detail/format_base.hpp | 6 +---- include/sharg/detail/format_tdl.hpp | 30 ++++++++++++++++++++++++- include/sharg/detail/to_string.hpp | 8 +++++++ include/sharg/parser.hpp | 21 ++++------------- test/documentation/sharg_doxygen_cfg.in | 3 ++- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/include/sharg/detail/format_base.hpp b/include/sharg/detail/format_base.hpp index acbae6e9..6a15b8d3 100644 --- a/include/sharg/detail/format_base.hpp +++ b/include/sharg/detail/format_base.hpp @@ -340,11 +340,7 @@ class format_help_base : public format_base derived_t().print_list_item("\\fB--copyright\\fP", "Prints the copyright/license information."); derived_t().print_list_item("\\fB--export-help\\fP (std::string)", "Export the help page information. Value must be one of " -#if SHARG_HAS_TDL - "[html, man, ctd, cwl]."); -#else - "[html, man]."); -#endif + + detail::supported_exports + "."); if (version_check_dev_decision == update_notifications::on) derived_t().print_list_item("\\fB--version-check\\fP (bool)", "Whether to check for the newest app version. Default: true."); diff --git a/include/sharg/detail/format_tdl.hpp b/include/sharg/detail/format_tdl.hpp index 0b5de958..015cd9eb 100644 --- a/include/sharg/detail/format_tdl.hpp +++ b/include/sharg/detail/format_tdl.hpp @@ -14,7 +14,35 @@ #include -#if SHARG_HAS_TDL +#if !SHARG_HAS_TDL + +namespace sharg::detail +{ + +struct format_tdl : public format_help +{ + enum class FileFormat + { + CTD, + CWL + }; + + format_tdl(FileFormat fileFormat) : fileFormat{fileFormat} + {} + + FileFormat fileFormat; + + void parse(parser_meta_data &, std::vector const &) + { + throw validation_error{"Validation failed for option --export-help: " + "Value must be one of " + + detail::supported_exports + "."}; + } +}; + +} // namespace sharg::detail + +#else # include # include diff --git a/include/sharg/detail/to_string.hpp b/include/sharg/detail/to_string.hpp index 11f04b53..a64817a5 100644 --- a/include/sharg/detail/to_string.hpp +++ b/include/sharg/detail/to_string.hpp @@ -20,6 +20,14 @@ namespace sharg::detail { +//!\brief A string containing all supported export formats. +static std::string const supported_exports = +#if SHARG_HAS_TDL + "[html, man, ctd, cwl]"; +#else + "[html, man]"; +#endif + /*!\brief Streams all parameters via std::ostringstream and returns a concatenated string. * \ingroup misc * \tparam value_types Must be sharg::ostreamable (stream << value). diff --git a/include/sharg/parser.hpp b/include/sharg/parser.hpp index 10278a71..7e22e285 100644 --- a/include/sharg/parser.hpp +++ b/include/sharg/parser.hpp @@ -436,16 +436,10 @@ class parser std::visit( [this](T & f) { -#if SHARG_HAS_TDL if constexpr (std::same_as) - { f.parse(info, executable_name); - } else -#endif - { f.parse(info); - } }, format); parse_was_called = true; @@ -719,11 +713,9 @@ class parser detail::format_version, detail::format_html, detail::format_man, -#if SHARG_HAS_TDL detail::format_tdl, -#endif - detail::format_copyright/*, - detail::format_ctd*/> format{detail::format_help{{}, {}, false}}; // Will be overwritten in any case. + detail::format_copyright> + format{detail::format_help{{}, {}, false}}; // Will be overwritten in any case. //!\brief List of option/flag identifiers that are already used. std::set used_option_ids{"h", "hh", "help", "advanced-help", "export-help", "version", "copyright"}; @@ -839,19 +831,14 @@ class parser format = detail::format_html{subcommands, version_check_dev_decision}; else if (export_format == "man") format = detail::format_man{subcommands, version_check_dev_decision}; -#if SHARG_HAS_TDL else if (export_format == "ctd") format = detail::format_tdl{detail::format_tdl::FileFormat::CTD}; else if (export_format == "cwl") format = detail::format_tdl{detail::format_tdl::FileFormat::CWL}; else throw validation_error{"Validation failed for option --export-help: " - "Value must be one of [html, man, ctd, cwl]."}; -#else - else - throw validation_error{"Validation failed for option --export-help: " - "Value must be one of [html, man]."}; -#endif + "Value must be one of " + + detail::supported_exports + "."}; special_format_was_set = true; } else if (arg == "--copyright") diff --git a/test/documentation/sharg_doxygen_cfg.in b/test/documentation/sharg_doxygen_cfg.in index 70d5a865..862eb45a 100644 --- a/test/documentation/sharg_doxygen_cfg.in +++ b/test/documentation/sharg_doxygen_cfg.in @@ -336,7 +336,8 @@ PREDEFINED = "CEREAL_SERIALIZE_FUNCTION_NAME=serialize" \ "CEREAL_LOAD_MINIMAL_FUNCTION_NAME=load_minimal" \ "CEREAL_SAVE_MINIMAL_FUNCTION_NAME=save_minimal" \ "SHARG_DOXYGEN_ONLY(x)= x" \ - "${SHARG_DOXYGEN_PREDEFINED_NDEBUG}" + "${SHARG_DOXYGEN_PREDEFINED_NDEBUG}" \ + "SHARG_HAS_TDL=1" EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = NO #---------------------------------------------------------------------------