| 623 | } |
| 624 | |
| 625 | std::string RPCHelpMan::ToString() const |
| 626 | { |
| 627 | std::string ret; |
| 628 | |
| 629 | // Oneline summary |
| 630 | ret += m_name; |
| 631 | bool was_optional{false}; |
| 632 | for (const auto& arg : m_args) { |
| 633 | if (arg.m_hidden) break; // Any arg that follows is also hidden |
| 634 | const bool optional = arg.IsOptional(); |
| 635 | ret += " "; |
| 636 | if (optional) { |
| 637 | if (!was_optional) ret += "( "; |
| 638 | was_optional = true; |
| 639 | } else { |
| 640 | if (was_optional) ret += ") "; |
| 641 | was_optional = false; |
| 642 | } |
| 643 | ret += arg.ToString(/* oneline */ true); |
| 644 | } |
| 645 | if (was_optional) ret += " )"; |
| 646 | |
| 647 | // Description |
| 648 | ret += "\n\n" + TrimString(m_description) + "\n"; |
| 649 | |
| 650 | // Arguments |
| 651 | Sections sections; |
| 652 | for (size_t i{0}; i < m_args.size(); ++i) { |
| 653 | const auto& arg = m_args.at(i); |
| 654 | if (arg.m_hidden) break; // Any arg that follows is also hidden |
| 655 | |
| 656 | if (i == 0) ret += "\nArguments:\n"; |
| 657 | |
| 658 | // Push named argument name and description |
| 659 | sections.m_sections.emplace_back(::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString()); |
| 660 | sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size()); |
| 661 | |
| 662 | // Recursively push nested args |
| 663 | sections.Push(arg); |
| 664 | } |
| 665 | ret += sections.ToString(); |
| 666 | |
| 667 | // Result |
| 668 | ret += m_results.ToDescriptionString(); |
| 669 | |
| 670 | // Examples |
| 671 | ret += m_examples.ToDescriptionString(); |
| 672 | |
| 673 | return ret; |
| 674 | } |
| 675 | |
| 676 | UniValue RPCHelpMan::GetArgMap() const |
| 677 | { |