Skip to content

Commit

Permalink
reworked alias command
Browse files Browse the repository at this point in the history
  • Loading branch information
void-inject committed Jan 8, 2025
1 parent 58fd3bd commit 5e914d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
1 change: 0 additions & 1 deletion library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class interactor_impl : public interactor
interactor& removeCommand(const std::string& action) override;
std::vector<std::string> getCommandActions() const override;
std::unordered_map<std::string, std::string> aliasMap;
void alias(const std::string& action, const std::string& value);
bool triggerCommand(std::string_view command) override;

interactor& initBindings() override;
Expand Down
31 changes: 17 additions & 14 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -802,18 +802,6 @@ std::vector<std::string> interactor_impl::getCommandActions() const
return actions;
}

//----------------------------------------------------------------------------
void interactor_impl::alias(const std::string& action, const std::string& value)
{
if (action.empty() || value.empty())
{
log::error("Alias action or value cannot be empty.");
return;
}
aliasMap[action] = value;
log::error("Alias added: " + action + " -> " + value);
}

//----------------------------------------------------------------------------
bool interactor_impl::triggerCommand(std::string_view command)
{
Expand All @@ -836,12 +824,27 @@ bool interactor_impl::triggerCommand(std::string_view command)

std::string action = tokens[0];

// Check if action is an alias
// **Handle Alias Command**
if (action == "alias")
{
if (tokens.size() != 3)

Check warning on line 830 in library/src/interactor_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/interactor_impl.cxx#L830

Added line #L830 was not covered by tests
{
log::error("Alias command requires exactly 2 arguments: alias <name> <something>");
return false;

Check warning on line 833 in library/src/interactor_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/interactor_impl.cxx#L832-L833

Added lines #L832 - L833 were not covered by tests
}
const std::string& aliasName = tokens[1];
const std::string& aliasCommand = tokens[2];
aliasMap[aliasName] = aliasCommand;
log::info("Alias added: ", aliasName, "", aliasCommand);
return true;

Check warning on line 839 in library/src/interactor_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/interactor_impl.cxx#L835-L839

Added lines #L835 - L839 were not covered by tests
}

// **Resolve Alias**
auto aliasIt = aliasMap.find(action);
if (aliasIt != aliasMap.end())
{
action = aliasIt->second;
log::error("Alias resolved: " + action);
log::info("Alias resolved: ", action);

Check warning on line 847 in library/src/interactor_impl.cxx

View check run for this annotation

Codecov / codecov/patch

library/src/interactor_impl.cxx#L846-L847

Added lines #L846 - L847 were not covered by tests
}

try
Expand Down

0 comments on commit 5e914d1

Please sign in to comment.