core/command: deprecate qs msg

This commit is contained in:
outfoxxed 2025-01-25 01:00:42 -08:00
parent 420529362f
commit 9417d6fa57
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 53 additions and 32 deletions

View file

@ -285,26 +285,21 @@ int killInstances(CommandState& cmd) {
}); });
} }
int msgInstance(CommandState& cmd) { int ipcCommand(CommandState& cmd) {
InstanceLockInfo instance; InstanceLockInfo instance;
auto r = selectInstance(cmd, &instance); auto r = selectInstance(cmd, &instance);
if (r != 0) return r; if (r != 0) return r;
return IpcClient::connect(instance.instance.instanceId, [&](IpcClient& client) { return IpcClient::connect(instance.instance.instanceId, [&](IpcClient& client) {
if (cmd.ipc.info) { if (*cmd.ipc.show || cmd.ipc.showOld) {
return qs::io::ipc::comm::queryMetadata(&client, *cmd.ipc.target, *cmd.ipc.function); return qs::io::ipc::comm::queryMetadata(&client, *cmd.ipc.target, *cmd.ipc.name);
} else { } else {
QVector<QString> arguments; QVector<QString> arguments;
for (auto& arg: cmd.ipc.arguments) { for (auto& arg: cmd.ipc.arguments) {
arguments += *arg; arguments += *arg;
} }
return qs::io::ipc::comm::callFunction( return qs::io::ipc::comm::callFunction(&client, *cmd.ipc.target, *cmd.ipc.name, arguments);
&client,
*cmd.ipc.target,
*cmd.ipc.function,
arguments
);
} }
return -1; return -1;
@ -423,8 +418,8 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) {
return listInstances(state); return listInstances(state);
} else if (*state.subcommand.kill) { } else if (*state.subcommand.kill) {
return killInstances(state); return killInstances(state);
} else if (*state.subcommand.msg) { } else if (*state.subcommand.msg || *state.ipc.ipc) {
return msgInstance(state); return ipcCommand(state);
} else { } else {
if (strcmp(qVersion(), QT_VERSION_STR) != 0) { if (strcmp(qVersion(), QT_VERSION_STR) != 0) {
qWarning() << "\033[31mQuickshell was built against Qt" << QT_VERSION_STR qWarning() << "\033[31mQuickshell was built against Qt" << QT_VERSION_STR

View file

@ -68,9 +68,12 @@ struct CommandState {
} output; } output;
struct { struct {
bool info = false; CLI::App* ipc = nullptr;
CLI::App* show = nullptr;
CLI::App* call = nullptr;
bool showOld = false;
QStringOption target; QStringOption target;
QStringOption function; QStringOption name;
std::vector<QStringOption> arguments; std::vector<QStringOption> arguments;
} ipc; } ipc;

View file

@ -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."); ->description("Rules to apply to the log being read, in the format of QT_LOGGING_RULES.");
auto* instance = addInstanceSelection(sub)->excludes(file); auto* instance = addInstanceSelection(sub)->excludes(file);
addConfigSelection(sub)->excludes(instance)->excludes(file); addConfigSelection(sub, true)->excludes(instance)->excludes(file);
addLoggingOptions(sub, false); addLoggingOptions(sub, false);
state.subcommand.log = sub; 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* sub = cli->add_subcommand("ipc", "Communicate with other Quickshell instances.")
->require_subcommand();
auto* target = sub->add_option("target", state.ipc.target, "The target to message."); state.ipc.ipc = sub;
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* instance = addInstanceSelection(sub); auto* instance = addInstanceSelection(sub);
addConfigSelection(sub, true)->excludes(instance); addConfigSelection(sub, true)->excludes(instance);
addLoggingOptions(sub, false, true); 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; state.subcommand.msg = sub;
} }