From 53fc018adaa566466c78c7feb5eaa2be49f91464 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 28 Jan 2025 19:47:20 +0100 Subject: [PATCH] fix: --pl subcommand not working correctly anymore --- lib/libimhex/include/hex/api/plugin_manager.hpp | 6 ++++++ lib/libimhex/source/subcommands/subcommands.cpp | 2 +- plugins/builtin/source/plugin_builtin.cpp | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/include/hex/api/plugin_manager.hpp b/lib/libimhex/include/hex/api/plugin_manager.hpp index fe60109c0..0471e7f43 100644 --- a/lib/libimhex/include/hex/api/plugin_manager.hpp +++ b/lib/libimhex/include/hex/api/plugin_manager.hpp @@ -15,11 +15,17 @@ struct ImGuiContext; namespace hex { struct SubCommand { + enum class Type : u8 { + Option, + SubCommand + }; + std::string commandLong; std::string commandShort; std::string commandDescription; std::function&)> callback; + Type type = Type::Option; }; struct Feature { diff --git a/lib/libimhex/source/subcommands/subcommands.cpp b/lib/libimhex/source/subcommands/subcommands.cpp index 03f6bd9f0..557ec6ae5 100644 --- a/lib/libimhex/source/subcommands/subcommands.cpp +++ b/lib/libimhex/source/subcommands/subcommands.cpp @@ -53,7 +53,7 @@ namespace hex::subcommands { while (argsIter != args.end()) { const std::string &arg = *argsIter; - if (!currentSubCommandArgs.empty() && arg.starts_with("--")) { + if (!currentSubCommandArgs.empty() && arg.starts_with("--") && !(currentSubCommand.has_value() && currentSubCommand->type == SubCommand::Type::SubCommand)) { // Save command to run if (currentSubCommand) { subCommands.emplace_back(*currentSubCommand, currentSubCommandArgs); diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 66e045b5d..065127728 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -76,7 +76,7 @@ IMHEX_PLUGIN_SUBCOMMANDS() { { "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand }, { "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand }, { "magic", "", "Identify file types", hex::plugin::builtin::handleMagicCommand }, - { "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand }, + { "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand, SubCommand::Type::SubCommand }, { "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, { "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, { "reset-settings", "", "Resets all settings back to default", hex::plugin::builtin::handleSettingsResetCommand },