From: Miod Vallat Date: Thu, 23 Jan 2025 14:28:26 +0000 (+0100) Subject: Add a command alias table. X-Git-Tag: dnsdist-2.0.0-alpha1~29^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16137033bd4b6b8ac80f9751722838579b872647;p=thirdparty%2Fpdns.git Add a command alias table. This replaces "did you mean bar?" when running pdnsutil foo, and instead invokes bar directly. --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index c2449d36b5..b896e7f6fb 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -2748,18 +2748,6 @@ static int listMemberZones(vector& cmds, const std::string_view synopsis return listMemberZones(cmds.at(1)); } -static int testZone([[maybe_unused]] vector& cmds, [[maybe_unused]] const std::string_view synopsis) -{ - cerr << "Did you mean check-zone?"<& cmds, [[maybe_unused]] const std::string_view synopsis) -{ - cerr << "Did you mean check-all-zones?"<& cmds, const std::string_view synopsis) { if(cmds.size() < 3) { @@ -4702,15 +4690,11 @@ static const std::unordered_map commands{ ""}}, // TODO: short help line {"test-algorithms", {false, testAlgorithms, GROUP_OTHER, "", ""}}, // TODO: synopsis and short help line - {"test-all-zones", {true, testAllZones, GROUP_ZONE, - "", ""}}, // TODO: synopsis and short help line {"test-schema", {true, testSchema, GROUP_OTHER, "test-schema ZONE", "\tTest DB schema - will create ZONE"}}, {"test-speed", {true, testSpeed, GROUP_OTHER, "test-speed ZONE NUM_CORES", ""}}, // TODO: short help line - {"test-zone", {true, testZone, GROUP_ZONE, - "", ""}}, // TODO: synopsis and short help line {"unpublish-zone-key", {true, unpublishZoneKey, GROUP_ZONEKEY, "unpublish-zone-key ZONE KEY_ID", "\tUnpublish the zone key with key id KEY_ID in ZONE"}}, @@ -4734,6 +4718,11 @@ static const std::unordered_map commands{ }; // clang-format on +static const std::unordered_map aliases{ + {"test-zone", "check-zone"}, + {"test-all-zones", "check-all-zones"} +}; + int main(int argc, char** argv) try { @@ -4797,13 +4786,22 @@ try loadMainConfig(g_vm["config-dir"].as()); - const auto iter = commands.find(cmds.at(0)); - if (iter != commands.end()) { - const auto dispatcher = iter->second; - if (dispatcher.requiresInitialization) { + const commandDispatcher* dispatcher{nullptr}; + if (const auto iter = commands.find(cmds.at(0)); iter != commands.end()) { + dispatcher = &iter->second; + } + if (dispatcher == nullptr) { + if (const auto alias = aliases.find(cmds.at(0)); alias != aliases.end()) { + if (const auto iter = commands.find(alias->second); iter != commands.end()) { + dispatcher = &iter->second; + } + } + } + if (dispatcher != nullptr) { + if (dispatcher->requiresInitialization) { reportAllTypes(); } - return dispatcher.handler(cmds, dispatcher.synopsis); + return dispatcher->handler(cmds, dispatcher->synopsis); } cerr << "Unknown command '" << cmds.at(0) << "'" << endl;