From 9417d6fa57a1c0a7c711dcdeeb7c43d150382e30 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sat, 25 Jan 2025 01:00:42 -0800 Subject: [PATCH] core/command: deprecate `qs msg` --- src/launch/command.cpp | 17 ++++------- src/launch/launch_p.hpp | 7 +++-- src/launch/parsecommand.cpp | 61 +++++++++++++++++++++++++------------ 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/launch/command.cpp b/src/launch/command.cpp index 449fab79..f814b5ff 100644 --- a/src/launch/command.cpp +++ b/src/launch/command.cpp @@ -285,26 +285,21 @@ int killInstances(CommandState& cmd) { }); } -int msgInstance(CommandState& cmd) { +int ipcCommand(CommandState& cmd) { InstanceLockInfo instance; auto r = selectInstance(cmd, &instance); if (r != 0) return r; return IpcClient::connect(instance.instance.instanceId, [&](IpcClient& client) { - if (cmd.ipc.info) { - return qs::io::ipc::comm::queryMetadata(&client, *cmd.ipc.target, *cmd.ipc.function); + if (*cmd.ipc.show || cmd.ipc.showOld) { + return qs::io::ipc::comm::queryMetadata(&client, *cmd.ipc.target, *cmd.ipc.name); } else { QVector arguments; for (auto& arg: cmd.ipc.arguments) { arguments += *arg; } - return qs::io::ipc::comm::callFunction( - &client, - *cmd.ipc.target, - *cmd.ipc.function, - arguments - ); + return qs::io::ipc::comm::callFunction(&client, *cmd.ipc.target, *cmd.ipc.name, arguments); } return -1; @@ -423,8 +418,8 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) { return listInstances(state); } else if (*state.subcommand.kill) { return killInstances(state); - } else if (*state.subcommand.msg) { - return msgInstance(state); + } else if (*state.subcommand.msg || *state.ipc.ipc) { + return ipcCommand(state); } else { if (strcmp(qVersion(), QT_VERSION_STR) != 0) { qWarning() << "\033[31mQuickshell was built against Qt" << QT_VERSION_STR diff --git a/src/launch/launch_p.hpp b/src/launch/launch_p.hpp index 1b59de86..a9a515c4 100644 --- a/src/launch/launch_p.hpp +++ b/src/launch/launch_p.hpp @@ -68,9 +68,12 @@ struct CommandState { } output; struct { - bool info = false; + CLI::App* ipc = nullptr; + CLI::App* show = nullptr; + CLI::App* call = nullptr; + bool showOld = false; QStringOption target; - QStringOption function; + QStringOption name; std::vector arguments; } ipc; diff --git a/src/launch/parsecommand.cpp b/src/launch/parsecommand.cpp index 9a88c4f5..2c082fec 100644 --- a/src/launch/parsecommand.cpp +++ b/src/launch/parsecommand.cpp @@ -135,7 +135,7 @@ int parseCommand(int argc, char** argv, CommandState& state) { ->description("Rules to apply to the log being read, in the format of QT_LOGGING_RULES."); auto* instance = addInstanceSelection(sub)->excludes(file); - addConfigSelection(sub)->excludes(instance)->excludes(file); + addConfigSelection(sub, true)->excludes(instance)->excludes(file); addLoggingOptions(sub, false); state.subcommand.log = sub; @@ -168,29 +168,52 @@ int parseCommand(int argc, char** argv, CommandState& state) { } { - auto* sub = cli->add_subcommand("msg", "Send messages to IpcHandlers.")->require_option(); - - auto* target = sub->add_option("target", state.ipc.target, "The target to message."); - - auto* function = sub->add_option("function", state.ipc.function) - ->description("The function to call in the target.") - ->needs(target); - - auto* arguments = sub->add_option("arguments", state.ipc.arguments) - ->description("Arguments to the called function.") - ->needs(function) - ->allow_extra_args(); - - sub->add_flag("-s,--show", state.ipc.info) - ->description("Print information about a function or target if given, or all available " - "targets if not.") - ->excludes(arguments); + auto* sub = cli->add_subcommand("ipc", "Communicate with other Quickshell instances.") + ->require_subcommand(); + state.ipc.ipc = sub; auto* instance = addInstanceSelection(sub); addConfigSelection(sub, true)->excludes(instance); addLoggingOptions(sub, false, true); - sub->require_option(); + { + auto* show = sub->add_subcommand("show", "Print information about available IPC targets."); + state.ipc.show = show; + } + + { + auto* call = sub->add_subcommand("call", "Call an IpcHandler function."); + state.ipc.call = call; + + call->add_option("target", state.ipc.target, "The target to message."); + + call->add_option("function", state.ipc.name) + ->description("The function to call in the target."); + + call->add_option("arguments", state.ipc.arguments) + ->description("Arguments to the called function.") + ->allow_extra_args(); + } + } + + { + auto* sub = cli->add_subcommand("msg", "[DEPRECATED] Moved to `ipc call`.")->require_option(); + + sub->add_option("target", state.ipc.target, "The target to message."); + + sub->add_option("function", state.ipc.name)->description("The function to call in the target."); + + sub->add_option("arguments", state.ipc.arguments) + ->description("Arguments to the called function.") + ->allow_extra_args(); + + sub->add_flag("-s,--show", state.ipc.showOld) + ->description("Print information about a function or target if given, or all available " + "targets if not."); + + auto* instance = addInstanceSelection(sub); + addConfigSelection(sub, true)->excludes(instance); + addLoggingOptions(sub, false, true); state.subcommand.msg = sub; }