allow enable to interpret aliases

develop
Myk Taylor 2023-03-24 23:25:24 -07:00
parent d67d57af3d
commit 2bc92042a5
No known key found for this signature in database
3 changed files with 10 additions and 6 deletions

@ -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) - `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) - `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 - `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 ## Documentation

@ -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]; Plugin * plug = (*plug_mgr)[part];
if(!plug) if(!plug)
@ -2657,13 +2659,14 @@ std::map<std::string, std::vector<std::string>> Core::ListAliases()
return aliases; 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<std::recursive_mutex> lock(alias_mutex); std::lock_guard<std::recursive_mutex> lock(alias_mutex);
if (IsAlias(name)) if (!IsAlias(name) || aliases[name].empty())
return name;
if (ignore_params)
return aliases[name][0];
return join_strings(" ", aliases[name]); return join_strings(" ", aliases[name]);
else
return default_;
} }
///////////////// /////////////////

@ -173,7 +173,7 @@ namespace DFHack
bool RunAlias(color_ostream &out, const std::string &name, bool RunAlias(color_ostream &out, const std::string &name,
const std::vector<std::string> &parameters, command_result &result); const std::vector<std::string> &parameters, command_result &result);
std::map<std::string, std::vector<std::string>> ListAliases(); std::map<std::string, std::vector<std::string>> 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(); std::string getHackPath();