Skip to content

Commit 6d8c1c8

Browse files
committed
fix: fix command compatibility
1 parent 5c12247 commit 6d8c1c8

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/legacy/api/CommandAPI.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,17 @@ void onExecute(CommandOrigin const& origin, CommandOutput& output, RuntimeComman
375375
if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
376376
auto& param = runtime[info.enumName];
377377
args.set(info.name, convertResult(param, origin, output));
378+
if (!info.identifier.empty()
379+
&& info.identifier != info.name) { // Keep compatibility with old plugins
380+
args.set(info.identifier, convertResult(param, origin, output));
381+
}
378382
} else {
379383
auto& param = runtime[info.name];
380384
args.set(info.name, convertResult(param, origin, output));
385+
if (!info.identifier.empty()
386+
&& info.identifier != info.name) { // Keep compatibility with old plugins
387+
args.set(info.identifier, convertResult(param, origin, output));
388+
}
381389
}
382390
}
383391
} catch (std::out_of_range&) {
@@ -411,7 +419,8 @@ Local<Value> CommandClass::newParameter(const Arguments& args) {
411419
option = (CommandParameterOption)args[index++].asNumber().toInt32();
412420
if (index != args.size()) throw std::runtime_error("Error Argument in newParameter");
413421

414-
getEngineOwnData()->plugin->registeredCommands[commandName].push_back({name, type, optional, enumName, option}
422+
getEngineOwnData()->plugin->registeredCommands[commandName].push_back(
423+
{name, type, optional, enumName, option, identifier}
415424
); // Stores the parameter name for onExecute use
416425

417426
return Boolean::newBoolean(true);
@@ -437,7 +446,8 @@ Local<Value> CommandClass::mandatory(const Arguments& args) {
437446
option = (CommandParameterOption)args[index++].asNumber().toInt32();
438447
if (index != args.size()) throw std::runtime_error("Error Argument in newParameter");
439448

440-
getEngineOwnData()->plugin->registeredCommands[commandName].push_back({name, type, false, enumName, option}
449+
getEngineOwnData()->plugin->registeredCommands[commandName].push_back(
450+
{name, type, false, enumName, option, identifier}
441451
); // Stores the parameter name for onExecute use
442452

443453
return Boolean::newBoolean(true);
@@ -463,7 +473,8 @@ Local<Value> CommandClass::optional(const Arguments& args) {
463473
option = (CommandParameterOption)args[index++].asNumber().toInt32();
464474
if (index != args.size()) throw std::runtime_error("Error Argument in newParameter");
465475

466-
getEngineOwnData()->plugin->registeredCommands[commandName].push_back({name, type, true, enumName, option}
476+
getEngineOwnData()->plugin->registeredCommands[commandName].push_back(
477+
{name, type, true, enumName, option, identifier}
467478
); // Stores the parameter name for onExecute use
468479

469480
return Boolean::newBoolean(true);
@@ -479,7 +490,7 @@ Local<Value> CommandClass::addOverload(const Arguments& args) {
479490
)](RuntimeOverload& cmd, std::string const& commandName, std::string const& paramName) {
480491
auto& paramList = getEngineData(e)->plugin->registeredCommands[commandName];
481492
for (auto& info : paramList) {
482-
if (info.name == paramName || info.enumName == paramName) {
493+
if (info.name == paramName || info.enumName == paramName || info.identifier == paramName) {
483494
if (info.optional) {
484495
if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
485496
cmd.optional(info.enumName, info.type, info.enumName).option(info.option);

src/legacy/main/NodeJsHelper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,8 @@ int executeNpmCommand(std::string cmd, std::string workingDir) {
363363
lse::getSelfModInstance().getLogger().error("Fail to execute NPM command. Error occurs");
364364
ll::error_utils::printCurrentException(lse::getSelfModInstance().getLogger());
365365
}
366+
node::Stop(env);
366367
}
367-
368-
node::Stop(env);
369368
return exit_code;
370369
}
371370

src/lse/Plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Plugin : public ll::mod::Mod {
1717
bool optional;
1818
std::string enumName;
1919
CommandParameterOption option;
20+
std::string identifier;
2021
};
2122

2223
std::unordered_map<std::string, std::vector<ParamInfo>> registeredCommands;

0 commit comments

Comments
 (0)