1
0
mirror of synced 2025-02-06 14:14:22 +01:00

feat: Added short forms for commonly used commands

This commit is contained in:
WerWolv 2024-03-14 18:24:31 +01:00
parent f2309ba079
commit cbc31f3c18
4 changed files with 38 additions and 22 deletions

View File

@ -15,8 +15,10 @@ struct ImGuiContext;
namespace hex { namespace hex {
struct SubCommand { struct SubCommand {
std::string commandKey; std::string commandLong;
std::string commandDesc; std::string commandShort;
std::string commandDescription;
std::function<void(const std::vector<std::string>&)> callback; std::function<void(const std::vector<std::string>&)> callback;
}; };

View File

@ -15,7 +15,7 @@ namespace hex::subcommands {
std::optional<SubCommand> findSubCommand(const std::string &arg) { std::optional<SubCommand> findSubCommand(const std::string &arg) {
for (auto &plugin : PluginManager::getPlugins()) { for (auto &plugin : PluginManager::getPlugins()) {
for (auto &subCommand : plugin.getSubCommands()) { for (auto &subCommand : plugin.getSubCommands()) {
if (hex::format("--{}", subCommand.commandKey) == arg) { if (hex::format("--{}", subCommand.commandLong) == arg || hex::format("-{}", subCommand.commandShort) == arg) {
return subCommand; return subCommand;
} }
} }
@ -112,8 +112,8 @@ namespace hex::subcommands {
std::vector<std::string> args; std::vector<std::string> args;
for (const auto &arg_view : std::views::split(string, char(0x00))) { for (const auto &argument : std::views::split(string, char(0x00))) {
std::string arg(arg_view.data(), arg_view.size()); std::string arg(argument.data(), argument.size());
args.push_back(arg); args.push_back(arg);
} }

View File

@ -47,16 +47,30 @@ namespace hex::plugin::builtin {
"Available subcommands:\n" "Available subcommands:\n"
); );
size_t longestCommand = 0; size_t longestLongCommand = 0, longestShortCommand = 0;
for (const auto &plugin : PluginManager::getPlugins()) { for (const auto &plugin : PluginManager::getPlugins()) {
for (const auto &subCommand : plugin.getSubCommands()) { 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 &plugin : PluginManager::getPlugins()) {
for (const auto &subCommand : plugin.getSubCommands()) { 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
);
} }
} }

View File

@ -58,22 +58,22 @@ namespace hex::plugin::builtin {
} }
IMHEX_PLUGIN_SUBCOMMANDS() { IMHEX_PLUGIN_SUBCOMMANDS() {
{ "help", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, { "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand },
{ "version", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, { "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand },
{ "plugins", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, { "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand },
{ "language", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, { "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand },
{ "verbose", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, { "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 }, { "calc", "", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand },
{ "hash", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand }, { "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand },
{ "encode", "Encode a string", hex::plugin::builtin::handleEncodeCommand }, { "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand },
{ "decode", "Decode a string", hex::plugin::builtin::handleDecodeCommand }, { "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand },
{ "magic", "Identify file types", hex::plugin::builtin::handleMagicCommand }, { "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 },
{ "hexdump", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, { "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand },
{ "demangle", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, { "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand },
}; };
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") { IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {