diff --git a/lib/libimhex/include/hex/api/plugin_manager.hpp b/lib/libimhex/include/hex/api/plugin_manager.hpp index 111adeee5..786431be5 100644 --- a/lib/libimhex/include/hex/api/plugin_manager.hpp +++ b/lib/libimhex/include/hex/api/plugin_manager.hpp @@ -15,8 +15,10 @@ struct ImGuiContext; namespace hex { struct SubCommand { - std::string commandKey; - std::string commandDesc; + std::string commandLong; + std::string commandShort; + + std::string commandDescription; std::function&)> callback; }; diff --git a/lib/libimhex/source/subcommands/subcommands.cpp b/lib/libimhex/source/subcommands/subcommands.cpp index 2336222cc..e089f529d 100644 --- a/lib/libimhex/source/subcommands/subcommands.cpp +++ b/lib/libimhex/source/subcommands/subcommands.cpp @@ -15,7 +15,7 @@ namespace hex::subcommands { std::optional findSubCommand(const std::string &arg) { for (auto &plugin : PluginManager::getPlugins()) { for (auto &subCommand : plugin.getSubCommands()) { - if (hex::format("--{}", subCommand.commandKey) == arg) { + if (hex::format("--{}", subCommand.commandLong) == arg || hex::format("-{}", subCommand.commandShort) == arg) { return subCommand; } } @@ -112,8 +112,8 @@ namespace hex::subcommands { std::vector args; - for (const auto &arg_view : std::views::split(string, char(0x00))) { - std::string arg(arg_view.data(), arg_view.size()); + for (const auto &argument : std::views::split(string, char(0x00))) { + std::string arg(argument.data(), argument.size()); args.push_back(arg); } diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index f3db75a17..75dc8ec11 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -47,16 +47,30 @@ namespace hex::plugin::builtin { "Available subcommands:\n" ); - size_t longestCommand = 0; + size_t longestLongCommand = 0, longestShortCommand = 0; for (const auto &plugin : PluginManager::getPlugins()) { for (const auto &subCommand : plugin.getSubCommands()) { - longestCommand = std::max(longestCommand, subCommand.commandKey.size()); + longestLongCommand = std::max(longestLongCommand, subCommand.commandLong.size()); + longestShortCommand = std::max(longestShortCommand, subCommand.commandShort.size()); } } for (const auto &plugin : PluginManager::getPlugins()) { for (const auto &subCommand : plugin.getSubCommands()) { - hex::log::println(" --{}{: <{}} {}", subCommand.commandKey, "", longestCommand - subCommand.commandKey.size(), subCommand.commandDesc); + hex::log::println(" " + "{}" + "{: <{}}" + "{}" + "{}" + "{: <{}}" + "{}", + subCommand.commandShort.empty() ? " " : "-", + subCommand.commandShort, longestShortCommand, + subCommand.commandShort.empty() ? " " : ", ", + subCommand.commandLong.empty() ? " " : "--", + subCommand.commandLong, longestLongCommand + 5, + subCommand.commandDescription + ); } } diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 7fd75a996..f04ce9843 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -58,22 +58,22 @@ namespace hex::plugin::builtin { } IMHEX_PLUGIN_SUBCOMMANDS() { - { "help", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, - { "version", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, - { "plugins", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, - { "language", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, - { "verbose", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, + { "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, + { "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, + { "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, + { "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, + { "verbose", "v", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, - { "open", "Open files passed as argument. [default]", hex::plugin::builtin::handleOpenCommand }, + { "open", "o", "Open files passed as argument. [default]", hex::plugin::builtin::handleOpenCommand }, - { "calc", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand }, - { "hash", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand }, - { "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 }, - { "hexdump", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, - { "demangle", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, + { "calc", "", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand }, + { "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand }, + { "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 }, + { "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, + { "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, }; IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {