Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias command #1815

Closed
wants to merge 18 commits into from
1 change: 1 addition & 0 deletions library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class interactor_impl : public interactor
std::string action, std::function<void(const std::vector<std::string>&)> callback) override;
interactor& removeCommand(const std::string& action) override;
std::vector<std::string> getCommandActions() const override;
std::unordered_map<std::string, std::string> aliasMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the one in the internals instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

bool triggerCommand(std::string_view command) override;

interactor& initBindings() override;
Expand Down
31 changes: 30 additions & 1 deletion library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ using mod_t = interaction_bind_t::ModifierKeys;

class interactor_impl::internals
{
//-------------------------------------------------------------------
private:
// Map to store aliases
std::map<std::string, std::string> aliasMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put that at the end of this class, next to the command map

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

//-------------------------------------------------------------------
public:
struct BindingCommands
{
Expand Down Expand Up @@ -817,7 +822,31 @@ bool interactor_impl::triggerCommand(std::string_view command)
return true;
}

const std::string& action = tokens[0];
std::string action = tokens[0];

// Handle Alias Command
if (action == "alias")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally alias command should be yet another command add added using addCommand

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i did it correct

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
if (tokens.size() != 3)
{
log::error("Alias command requires exactly 2 arguments: alias <name> <command>");
return false;
}
const std::string& aliasName = tokens[1];
const std::string& aliasCommand = tokens[2];
aliasMap[aliasName] = aliasCommand;
log::info("Alias added: ", aliasName, " → ", aliasCommand);
return true;
}

// Resolve Alias
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless Im mistaken this should be done even before tokenizing.

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

try
{
// Find the right command to call
Expand Down
5 changes: 5 additions & 0 deletions library/testing/TestSDKInteractorCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ int TestSDKInteractorCommand(int argc, char* argv[])
inter.triggerCommand("toggle model.scivis.cells");
test("triggerCommand toggle", options.model.scivis.cells == true);

// Test alias command
inter.triggerCommand("alias axis_off set ui.axis off");
inter.triggerCommand("axis_off");
test("triggerCommand alias resolve", options.ui.axis == false);

// triggerCommand error codepaths
test("triggerCommand toggle incompatible",
inter.triggerCommand("toggle scene.animation.index") == false);
Expand Down
Loading