16namespace sharg::detail
22class format_tdl :
public format_help
31 format_tdl(format_tdl
const &) =
default;
32 format_tdl & operator=(format_tdl
const &) =
default;
33 format_tdl(format_tdl &&) =
default;
34 format_tdl & operator=(format_tdl &&) =
default;
35 ~format_tdl() =
default;
37 format_tdl(FileFormat fileFormat) : fileFormat{fileFormat}
42 throw validation_error{
"Validation failed for option --export-help: "
43 "Value must be one of "
44 + detail::supported_exports +
"."};
47 FileFormat fileFormat;
61namespace sharg::detail
68inline auto to_tdl(
bool v)
70 return tdl::BoolValue(v);
76 return tdl::IntValue(v);
82 return tdl::DoubleValue(
static_cast<double>(v));
88 return tdl::StringValue(v);
92auto to_tdl(
auto SHARG_DOXYGEN_ONLY(v))
94 return tdl::BoolValue(
false);
105class format_tdl : format_base
109 enum class FileFormat : uint8_t
120 unsigned positional_option_count{0};
126 tdl::Node::Children parameters;
129 FileFormat fileFormat;
145 parser_meta_data meta;
154 format_tdl(FileFormat fileFormat) : fileFormat{fileFormat}
157 format_tdl(format_tdl
const &) =
default;
158 format_tdl & operator=(format_tdl
const &) =
default;
159 format_tdl(format_tdl &&) =
default;
160 format_tdl & operator=(format_tdl &&) =
default;
161 ~format_tdl() =
default;
166 template <
typename option_type,
typename val
idator_t>
167 void add_option(option_type & value, config<validator_t>
const & config)
169 auto description = config.description;
171 if (config.default_message.empty())
172 description += ((config.required) ?
std::string{} : get_default_message(value, value));
174 description += get_default_message(value, config.default_message);
176 if (
auto const & validator_message = config.validator.get_help_page_message(); !validator_message.empty())
177 description +=
". " + validator_message;
186 tags.insert(
"advanced");
191 store_help_page_element(
197 using Validator =
std::decay_t<
decltype(config.validator)>;
204 tags.insert(
"directory");
209 tags.insert(
"output");
213 tags.insert(
"directory");
214 tags.insert(
"output");
218 parameters.push_back(tdl::Node{.name = config.long_id, .description = description});
220 auto & node = parameters.back();
221 node.tags = std::move(tags);
222 node.value = tdl::StringValue{valueAsStr};
224 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
230 store_help_page_element(
234 parameters.push_back(tdl::Node{.name = config.long_id, .description = description});
236 auto & node = parameters.back();
237 node.tags = std::move(tags);
238 node.value = to_tdl(value);
240 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
249 template <
typename val
idator_t>
250 void add_flag(
bool & value, config<validator_t>
const & config)
252 store_help_page_element(
255 parameters.push_back(tdl::Node{
256 .name = config.long_id,
257 .description = config.description,
259 .value = to_tdl(value),
268 template <
typename option_type,
typename val
idator_t>
269 void add_positional_option(option_type & value, config<validator_t>
const & config)
272 auto positional_default_message = [&value]() ->
std::string
274 if constexpr (detail::is_container_option<option_type>)
276 return get_default_message(value, value);
285 auto positional_validator_message = [&config]() ->
std::string
287 if (
auto const & validator_message = config.validator.get_help_page_message(); !validator_message.empty())
288 return ". " + validator_message;
296 default_message = positional_default_message(),
299 auto id =
"positional_" +
std::to_string(positional_option_count);
300 ++positional_option_count;
301 auto description = config.description + default_message + validator_message;
303 parameters.push_back(tdl::Node{.name = id, .description = description});
305 auto & node = parameters.back();
307 if constexpr (detail::is_container_option<option_type>)
309 node.value = tdl::StringValueList{};
313 node.value = tdl::StringValue{};
314 node.tags.insert(
"required");
329 for (
auto && f : positional_option_calls)
333 for (
auto && f : parser_set_up_calls)
336 info.metaInfo = tdl::MetaInfo{
337 .version = meta.version,
338 .name = meta.app_name,
342 end(meta.description),
344 [](
auto const & a,
auto const & v)
350 if (!executable_name.
empty())
352 info.metaInfo.executableName = executable_name[0];
354 for (
size_t i{1}; i < executable_name.
size(); ++i)
356 parameters = {tdl::Node{
357 .name = executable_name[executable_name.
size() - i],
358 .tags = {
"basecommand"},
362 info.params = std::move(parameters);
364 if (fileFormat == FileFormat::CTD)
368 else if (fileFormat == FileFormat::CWL)
370 std::cout << tdl::convertToCWL(info) <<
"\n";
382 void add_section(
std::string const & SHARG_DOXYGEN_ONLY(title),
bool const SHARG_DOXYGEN_ONLY(advanced_only))
388 void add_subsection(
std::string const & SHARG_DOXYGEN_ONLY(title),
bool const SHARG_DOXYGEN_ONLY(advanced_only))
394 void add_line(
std::string const & SHARG_DOXYGEN_ONLY(text),
395 bool SHARG_DOXYGEN_ONLY(is_paragraph),
396 bool const SHARG_DOXYGEN_ONLY(advanced_only))
402 void add_list_item(
std::string const & SHARG_DOXYGEN_ONLY(key),
404 bool const SHARG_DOXYGEN_ONLY(advanced_only))
416 template <
typename val
idator_t>
421 parser_set_up_calls.push_back(std::move(printer));
Provides some standard validators for (positional) options.