Skip to content

Commit

Permalink
Maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jan 30, 2024
1 parent 641a878 commit 9ccc8ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
6 changes: 1 addition & 5 deletions include/sharg/detail/format_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
30 changes: 29 additions & 1 deletion include/sharg/detail/format_tdl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,35 @@

#include <sharg/platform.hpp>

#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<std::string> const &)
{
throw validation_error{"Validation failed for option --export-help: "
"Value must be one of "
+ detail::supported_exports + "."};
}
};

} // namespace sharg::detail

#else
# include <concepts>
# include <numeric>

Expand Down
8 changes: 8 additions & 0 deletions include/sharg/detail/to_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
21 changes: 4 additions & 17 deletions include/sharg/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,10 @@ class parser
std::visit(
[this]<typename T>(T & f)
{
#if SHARG_HAS_TDL
if constexpr (std::same_as<T, detail::format_tdl>)
{
f.parse(info, executable_name);
}
else
#endif
{
f.parse(info);
}
},
format);
parse_was_called = true;
Expand Down Expand Up @@ -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<std::string> used_option_ids{"h", "hh", "help", "advanced-help", "export-help", "version", "copyright"};
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion test/documentation/sharg_doxygen_cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
#---------------------------------------------------------------------------
Expand Down

0 comments on commit 9ccc8ec

Please sign in to comment.