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(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
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");
217 parameters.push_back(tdl::Node{
218 .name = config.long_id,
219 .description = description,
220 .tags = std::move(tags),
221 .value = tdl::StringValue{valueAsStr},
223 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
229 store_help_page_element(
232 parameters.push_back(tdl::Node{
233 .name = config.long_id,
234 .description = description,
235 .tags = std::move(tags),
236 .value = to_tdl(value),
238 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
247 template <
typename val
idator_t>
248 void add_flag(
bool & value, config<validator_t>
const & config)
250 store_help_page_element(
253 parameters.push_back(tdl::Node{
254 .name = config.long_id,
255 .description = config.description,
257 .value = to_tdl(value),
266 template <
typename option_type,
typename val
idator_t>
267 void add_positional_option(option_type & value, config<validator_t>
const & config)
270 auto positional_default_message = [&value]() ->
std::string
272 if constexpr (detail::is_container_option<option_type>)
274 return get_default_message(value, value);
283 auto positional_validator_message = [&config]() ->
std::string
285 if (
auto const & validator_message = config.validator.get_help_page_message(); !validator_message.empty())
286 return ". " + validator_message;
294 default_message = positional_default_message(),
297 auto id =
"positional_" +
std::to_string(positional_option_count);
298 ++positional_option_count;
299 auto description = config.description + default_message + validator_message;
301 parameters.push_back(tdl::Node{.name = id, .description = description});
303 auto & node = parameters.back();
305 if constexpr (detail::is_container_option<option_type>)
307 node.value = tdl::StringValueList{};
311 node.value = tdl::StringValue{};
312 node.tags.insert(
"required");
327 for (
auto f : positional_option_calls)
331 for (
auto f : parser_set_up_calls)
334 info.metaInfo = tdl::MetaInfo{
335 .version = meta.version,
336 .name = meta.app_name,
340 end(meta.description),
348 if (!executable_name.
empty())
350 info.metaInfo.executableName = executable_name[0];
352 for (
size_t i{1}; i < executable_name.
size(); ++i)
354 parameters = {tdl::Node{
355 .name = executable_name[executable_name.
size() - i],
356 .tags = {
"basecommand"},
360 info.params = std::move(parameters);
362 if (fileFormat == FileFormat::CTD)
366 else if (fileFormat == FileFormat::CWL)
368 std::cout << tdl::convertToCWL(info) <<
"\n";
380 void add_section(
std::string const & SHARG_DOXYGEN_ONLY(title),
bool const SHARG_DOXYGEN_ONLY(advanced_only))
386 void add_subsection(
std::string const & SHARG_DOXYGEN_ONLY(title),
bool const SHARG_DOXYGEN_ONLY(advanced_only))
392 void add_line(
std::string const & SHARG_DOXYGEN_ONLY(text),
393 bool SHARG_DOXYGEN_ONLY(is_paragraph),
394 bool const SHARG_DOXYGEN_ONLY(advanced_only))
400 void add_list_item(
std::string const & SHARG_DOXYGEN_ONLY(key),
402 bool const SHARG_DOXYGEN_ONLY(advanced_only))
414 template <
typename val
idator_t>
419 parser_set_up_calls.push_back(std::move(printer));
Provides some standard validators for (positional) options.