Skip to content

Commit

Permalink
rpc: Add option to hide RPCArg
Browse files Browse the repository at this point in the history
Summary:
Also, update switch statments to our style guide

This is a backport of [[bitcoin/bitcoin#19386 | core#19386]] [4/5]
bitcoin/bitcoin@aaaaad5

Depends on D10008

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10009
  • Loading branch information
MarcoFalke authored and PiRK committed Sep 10, 2021
1 parent f726df9 commit 924c562
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
27 changes: 11 additions & 16 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ struct Sections {
{indent + "]" + (outer_type != OuterType::NONE ? "," : ""),
""});
break;
}

// no default case, so the compiler can warn about missing cases
} // no default case, so the compiler can warn about missing cases
}
}

Expand Down Expand Up @@ -524,6 +522,9 @@ std::string RPCHelpMan::ToString() const {
ret += m_name;
bool was_optional{false};
for (const auto &arg : m_args) {
if (arg.m_hidden) {
continue;
}
const bool optional = arg.IsOptional();
ret += " ";
if (optional) {
Expand Down Expand Up @@ -551,6 +552,9 @@ std::string RPCHelpMan::ToString() const {
Sections sections;
for (size_t i{0}; i < m_args.size(); ++i) {
const auto &arg = m_args.at(i);
if (arg.m_hidden) {
continue;
}

if (i == 0) {
ret += "\nArguments:\n";
Expand Down Expand Up @@ -630,9 +634,7 @@ std::string RPCArg::ToDescriptionString() const {
case Type::ARR: {
ret += "json array";
break;
}

// no default case, so the compiler can warn about missing cases
} // no default case, so the compiler can warn about missing cases
}
}
if (m_fallback.which() == 1) {
Expand All @@ -651,9 +653,7 @@ std::string RPCArg::ToDescriptionString() const {
case RPCArg::Optional::NO: {
ret += ", required";
break;
}

// no default case, so the compiler can warn about missing cases
} // no default case, so the compiler can warn about missing cases
}
}
ret += ")";
Expand Down Expand Up @@ -762,11 +762,8 @@ void RPCResult::ToSections(Sections &sections, const OuterType outer_type,
}
sections.PushSection({indent + "}" + maybe_separator, ""});
return;
}

// no default case, so the compiler can warn about missing cases
} // no default case, so the compiler can warn about missing cases
}

CHECK_NONFATAL(false);
}

Expand Down Expand Up @@ -841,9 +838,7 @@ std::string RPCArg::ToString(const bool oneline) const {
res += i.ToString(oneline) + ",";
}
return "[" + res + "...]";
}

// no default case, so the compiler can warn about missing cases
} // no default case, so the compiler can warn about missing cases
}
CHECK_NONFATAL(false);
}
Expand Down
13 changes: 7 additions & 6 deletions src/rpc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct RPCArg {
//! aliases separated by | for named request arguments)
const std::string m_names;
const Type m_type;
const bool m_hidden;
//! Only used for arrays or dicts
const std::vector<RPCArg> m_inner;
const Fallback m_fallback;
Expand All @@ -194,8 +195,9 @@ struct RPCArg {
RPCArg(const std::string name, const Type type, const Fallback fallback,
const std::string description,
const std::string oneline_description = "",
const std::vector<std::string> type_str = {})
: m_names{std::move(name)}, m_type{std::move(type)},
const std::vector<std::string> type_str = {},
const bool hidden = false)
: m_names{std::move(name)}, m_type{std::move(type)}, m_hidden{hidden},
m_fallback{std::move(fallback)}, m_description{std::move(
description)},
m_oneline_description{std::move(oneline_description)},
Expand All @@ -207,10 +209,9 @@ struct RPCArg {
const std::string description, const std::vector<RPCArg> inner,
const std::string oneline_description = "",
const std::vector<std::string> type_str = {})
: m_names{std::move(name)}, m_type{std::move(type)}, m_inner{std::move(
inner)},
m_fallback{std::move(fallback)}, m_description{std::move(
description)},
: m_names{std::move(name)}, m_type{std::move(type)}, m_hidden{false},
m_inner{std::move(inner)}, m_fallback{std::move(fallback)},
m_description{std::move(description)},
m_oneline_description{std::move(oneline_description)},
m_type_str{std::move(type_str)} {
CHECK_NONFATAL(type == Type::ARR || type == Type::OBJ);
Expand Down

0 comments on commit 924c562

Please sign in to comment.