Skip to content

cli: add callJson ipc subcommand #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/launch/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ int ipcCommand(CommandState& cmd) {
return qs::io::ipc::comm::queryMetadata(&client, *cmd.ipc.target, *cmd.ipc.name);
} else if (*cmd.ipc.getprop) {
return qs::io::ipc::comm::getProperty(&client, *cmd.ipc.target, *cmd.ipc.name);
} else if (*cmd.ipc.callJson) {
return qs::io::ipc::comm::callFunction(
&client,
*cmd.ipc.target,
*cmd.ipc.name,
{*cmd.ipc.jsonArgument}
);
} else {
QVector<QString> arguments;
for (auto& arg: cmd.ipc.arguments) {
Expand Down
2 changes: 2 additions & 0 deletions src/launch/launch_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ struct CommandState {
CLI::App* ipc = nullptr;
CLI::App* show = nullptr;
CLI::App* call = nullptr;
CLI::App* callJson = nullptr;
CLI::App* getprop = nullptr;
bool showOld = false;
QStringOption target;
QStringOption name;
QStringOption jsonArgument;
std::vector<QStringOption> arguments;
} ipc;

Expand Down
16 changes: 16 additions & 0 deletions src/launch/parsecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ int parseCommand(int argc, char** argv, CommandState& state) {
->allow_extra_args();
}

{
auto* callJson = sub->add_subcommand(
"callJson",
"Call an IpcHandler function with a single JSON argument."
);
state.ipc.callJson = callJson;

callJson->add_option("target", state.ipc.target, "The target to message.");

callJson->add_option("function", state.ipc.name)
->description("The function to call in the target.");

callJson->add_option("json", state.ipc.jsonArgument)
->description("JSON string sent the called function.");
}

{
auto* prop =
sub->add_subcommand("prop", "Manipulate IpcHandler properties.")->require_subcommand();
Expand Down