| 7764 | } |
| 7765 | |
| 7766 | inline std::string ConfigBase::to_config(const App *app, bool default_also, bool write_description, |
| 7767 | std::string prefix) const { |
| 7768 | std::stringstream out; |
| 7769 | std::string commentLead; |
| 7770 | commentLead.push_back(commentChar); |
| 7771 | commentLead.push_back(' '); |
| 7772 | |
| 7773 | std::vector<std::string> groups = app->get_groups(); |
| 7774 | bool defaultUsed = false; |
| 7775 | groups.insert(groups.begin(), std::string("Options")); |
| 7776 | if (write_description) { |
| 7777 | out << commentLead << app->get_description() << '\n'; |
| 7778 | } |
| 7779 | for (auto &group : groups) { |
| 7780 | if (group == "Options" || group.empty()) { |
| 7781 | if (defaultUsed) { |
| 7782 | continue; |
| 7783 | } |
| 7784 | defaultUsed = true; |
| 7785 | } |
| 7786 | if (write_description && group != "Options" && !group.empty()) { |
| 7787 | out << '\n' << commentLead << group << " Options\n"; |
| 7788 | } |
| 7789 | for (const Option *opt : app->get_options({})) { |
| 7790 | // Only process option with a long-name and configurable |
| 7791 | if (!opt->get_lnames().empty() && opt->get_configurable()) { |
| 7792 | if (opt->get_group() != group) { |
| 7793 | if (!(group == "Options" && opt->get_group().empty())) { |
| 7794 | continue; |
| 7795 | } |
| 7796 | } |
| 7797 | std::string name = prefix + opt->get_lnames()[0]; |
| 7798 | std::string value = detail::ini_join(opt->reduced_results(), arraySeparator, arrayStart, arrayEnd); |
| 7799 | |
| 7800 | if (value.empty() && default_also) { |
| 7801 | if (!opt->get_default_str().empty()) { |
| 7802 | value = detail::convert_arg_for_ini(opt->get_default_str()); |
| 7803 | } else if (opt->get_expected_min() == 0) { |
| 7804 | value = "false"; |
| 7805 | } |
| 7806 | } |
| 7807 | |
| 7808 | if (!value.empty()) { |
| 7809 | if (write_description && opt->has_description()) { |
| 7810 | out << '\n'; |
| 7811 | out << commentLead << detail::fix_newlines(commentLead, opt->get_description()) << '\n'; |
| 7812 | } |
| 7813 | out << name << valueDelimiter << value << '\n'; |
| 7814 | } |
| 7815 | } |
| 7816 | } |
| 7817 | } |
| 7818 | auto subcommands = app->get_subcommands({}); |
| 7819 | for (const App *subcom : subcommands) { |
| 7820 | if (subcom->get_name().empty()) { |
| 7821 | if (write_description && !subcom->get_group().empty()) { |
| 7822 | out << '\n' << commentLead << subcom->get_group() << " Options\n"; |
| 7823 | } |
no test coverage detected