From 2bc92042a5b17266a4c425a14d8c73862949334b Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 24 Mar 2023 23:25:24 -0700 Subject: [PATCH] allow enable to interpret aliases --- docs/changelog.txt | 1 + library/Core.cpp | 13 ++++++++----- library/include/Core.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 11e552abe..7cb1fafcf 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -51,6 +51,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `stockpiles`: now includes a library of useful stockpile configs (see docs for details) - `automelt`: now allows metal chests to be melted (workaround for DF bug 2493 is no longer needed) - `orders`: add minimize button to overlay panel so you can get it out of the way to read long statue descriptions when choosing a subject in the details screen +- `enable`: can now interpret aliases defined with the `alias` command ## Documentation diff --git a/library/Core.cpp b/library/Core.cpp index 01bc89480..d55959ceb 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -763,6 +763,8 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, s } } + part = GetAliasCommand(part, true); + Plugin * plug = (*plug_mgr)[part]; if(!plug) @@ -2657,13 +2659,14 @@ std::map> Core::ListAliases() return aliases; } -std::string Core::GetAliasCommand(const std::string &name, const std::string &default_) +std::string Core::GetAliasCommand(const std::string &name, bool ignore_params) { std::lock_guard lock(alias_mutex); - if (IsAlias(name)) - return join_strings(" ", aliases[name]); - else - return default_; + if (!IsAlias(name) || aliases[name].empty()) + return name; + if (ignore_params) + return aliases[name][0]; + return join_strings(" ", aliases[name]); } ///////////////// diff --git a/library/include/Core.h b/library/include/Core.h index 6c99e62be..8232708b5 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -173,7 +173,7 @@ namespace DFHack bool RunAlias(color_ostream &out, const std::string &name, const std::vector ¶meters, command_result &result); std::map> ListAliases(); - std::string GetAliasCommand(const std::string &name, const std::string &default_ = ""); + std::string GetAliasCommand(const std::string &name, bool ignore_params = false); std::string getHackPath();