21#include <tdl/ParamDocumentToCTD.h>
22#include <tdl/ParamDocumentToCWL.h>
24namespace sharg::detail
31inline auto to_tdl(
bool v)
33 return tdl::BoolValue(v);
37auto to_tdl(std::integral
auto v)
39 return tdl::IntValue(v);
43auto to_tdl(std::floating_point
auto v)
45 return tdl::DoubleValue(v);
51 return tdl::StringValue(v);
55auto to_tdl(
auto SHARG_DOXYGEN_ONLY(v))
57 return tdl::BoolValue(
false);
68class format_tdl : format_base
83 unsigned positional_option_count{0};
91 FileFormat fileFormat;
107 parser_meta_data meta;
116 format_tdl(FileFormat fileFormat) : fileFormat{fileFormat}
119 format_tdl(format_tdl
const &) =
default;
120 format_tdl & operator=(format_tdl
const &) =
default;
121 format_tdl(format_tdl &&) =
default;
122 format_tdl & operator=(format_tdl &&) =
default;
123 ~format_tdl() =
default;
128 template <
typename option_type,
typename config_type>
129 void add_option(option_type & value, config_type
const & config)
131 auto description = config.description;
132 description += (config.required ?
std::string{
" "} : detail::to_string(
" Default: ", value,
". "));
133 description += config.validator.get_help_page_message();
142 tags.insert(
"advanced");
144 if constexpr (std::same_as<std::filesystem::path, option_type>)
147 store_help_page_element(
153 using Validator =
std::decay_t<
decltype(config.validator)>;
154 if constexpr (std::is_base_of_v<sharg::input_file_validator, Validator>)
158 else if constexpr (std::is_base_of_v<sharg::input_directory_validator, Validator>)
160 tags.insert(
"directory");
162 else if constexpr (std::is_base_of_v<sharg::output_file_validator, Validator>)
165 tags.insert(
"output");
167 else if constexpr (std::is_base_of_v<sharg::output_directory_validator, Validator>)
169 tags.insert(
"directory");
170 tags.insert(
"output");
173 info.params.push_back(tdl::Node{
174 .name = config.long_id,
175 .description = description,
176 .tags = std::move(tags),
177 .value = tdl::StringValue{valueAsStr},
179 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
185 store_help_page_element(
188 info.params.push_back(tdl::Node{
189 .name = config.long_id,
190 .description = description,
191 .tags = std::move(tags),
192 .value = to_tdl(value),
194 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
203 template <
typename config_type>
204 void add_flag(
bool & value, config_type
const & config)
206 store_help_page_element(
209 info.params.push_back(tdl::Node{
210 .name = config.long_id,
211 .description = config.description,
213 .value = to_tdl(value),
222 template <
typename option_type,
typename config_type>
223 void add_positional_option(option_type & value, config_type
const & config)
225 std::string msg = config.validator.get_help_page_message();
230 auto id =
"positional_" +
std::to_string(positional_option_count);
231 ++positional_option_count;
235 ((detail::is_container_option<option_type>) ? detail::to_string(
" Default: ", value,
". ")
239 info.params.push_back(tdl::Node{
241 .description = description,
243 .value = tdl::StringValue{},
245 if (!config.long_id.empty())
247 info.cliMapping.emplace_back(
"--" + config.long_id, config.long_id);
262 for (
auto f : positional_option_calls)
266 for (
auto f : parser_set_up_calls)
269 info.metaInfo = tdl::MetaInfo{
270 .version = meta.version,
271 .name = meta.app_name,
275 end(meta.description),
283 if (!executable_name.
empty())
285 info.metaInfo.executableName = executable_name[0];
287 for (
size_t i{1}; i < executable_name.
size(); ++i)
290 info.params.push_back(tdl::Node{
292 .value = tdl::StringValue(executable_name[i]),
294 info.cliMapping.emplace_back(
"", name);
297 if (fileFormat == FileFormat::CTD)
301 else if (fileFormat == FileFormat::CWL)
303 std::cout << tdl::convertToCWL(info) <<
"\n";
315 void add_section(
std::string const & SHARG_DOXYGEN_ONLY(title),
bool const SHARG_DOXYGEN_ONLY(advanced_only))
321 void add_subsection(
std::string const & SHARG_DOXYGEN_ONLY(title),
bool const SHARG_DOXYGEN_ONLY(advanced_only))
327 void add_line(
std::string const & SHARG_DOXYGEN_ONLY(text),
328 bool SHARG_DOXYGEN_ONLY(is_paragraph),
329 bool const SHARG_DOXYGEN_ONLY(advanced_only))
335 void add_list_item(
std::string const & SHARG_DOXYGEN_ONLY(key),
337 bool const SHARG_DOXYGEN_ONLY(advanced_only))
353 parser_set_up_calls.push_back(std::move(printer));
Provides some standard validators for (positional) options.