mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
impr: Make ImHex cli work more like other tools
This commit is contained in:
@@ -53,7 +53,7 @@ namespace hex::subcommands {
|
||||
while (argsIter != args.end()) {
|
||||
const std::string &arg = *argsIter;
|
||||
|
||||
if (arg == "--othercmd") {
|
||||
if (!currentSubCommandArgs.empty() && arg.starts_with("--")) {
|
||||
// Save command to run
|
||||
if (currentSubCommand) {
|
||||
subCommands.emplace_back(*currentSubCommand, currentSubCommandArgs);
|
||||
@@ -61,10 +61,10 @@ namespace hex::subcommands {
|
||||
|
||||
currentSubCommand = std::nullopt;
|
||||
currentSubCommandArgs = { };
|
||||
|
||||
} else if (currentSubCommand) {
|
||||
// Add current argument to the current command
|
||||
currentSubCommandArgs.push_back(arg);
|
||||
argsIter += 1;
|
||||
} else {
|
||||
// Get next subcommand from current argument
|
||||
currentSubCommand = findSubCommand(arg);
|
||||
@@ -72,9 +72,9 @@ namespace hex::subcommands {
|
||||
log::error("No subcommand named '{}' found", arg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
argsIter += 1;
|
||||
argsIter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Save last command to run
|
||||
@@ -83,8 +83,8 @@ namespace hex::subcommands {
|
||||
}
|
||||
|
||||
// Run the subcommands
|
||||
for (auto &[subcommand, args] : subCommands) {
|
||||
subcommand.callback(args);
|
||||
for (auto &[subcommand, subCommandArgs] : subCommands) {
|
||||
subcommand.callback(subCommandArgs);
|
||||
}
|
||||
|
||||
// Exit the process if it's not the main instance (the commands have been forwarded to another instance)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace hex::messaging {
|
||||
if (mkfifo(CommunicationPipePath, 0600) < 0) return;
|
||||
|
||||
static int fifo = 0;
|
||||
fifo = open(CommunicationPipePath, O_RDWR);
|
||||
fifo = open(CommunicationPipePath, O_RDWR | O_NONBLOCK);
|
||||
|
||||
static auto listenerThread = std::jthread([](const std::stop_token &stopToken){
|
||||
std::vector<u8> buffer(0xFFFF);
|
||||
@@ -46,9 +46,9 @@ namespace hex::messaging {
|
||||
int result = ::read(fifo, buffer.data(), buffer.size());
|
||||
if (result > 0) {
|
||||
EventNativeMessageReceived::post(std::vector<u8>{ buffer.begin(), buffer.begin() + result });
|
||||
} else {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -388,6 +388,9 @@ namespace hex::plugin::builtin {
|
||||
void registerCommandForwarders() {
|
||||
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){
|
||||
for (auto &arg : args) {
|
||||
if (arg.starts_with("--"))
|
||||
break;
|
||||
|
||||
RequestOpenFile::post(arg);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user