mirror of
https://github.com/swaywm/sway.git
synced 2024-11-21 23:41:27 +00:00
swaymsg: fix quiet error reporting
This makes it so swaymsg still returns the correct successful or failed error code when in quiet mode
This commit is contained in:
parent
c118618278
commit
c8e4ca355d
|
@ -397,6 +397,9 @@ int main(int argc, char **argv) {
|
||||||
if (!socket_path) {
|
if (!socket_path) {
|
||||||
socket_path = get_socketpath();
|
socket_path = get_socketpath();
|
||||||
if (!socket_path) {
|
if (!socket_path) {
|
||||||
|
if (quiet) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
sway_abort("Unable to retrieve socket path");
|
sway_abort("Unable to retrieve socket path");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,13 +433,18 @@ int main(int argc, char **argv) {
|
||||||
} else if (strcasecmp(cmdtype, "subscribe") == 0) {
|
} else if (strcasecmp(cmdtype, "subscribe") == 0) {
|
||||||
type = IPC_SUBSCRIBE;
|
type = IPC_SUBSCRIBE;
|
||||||
} else {
|
} else {
|
||||||
|
if (quiet) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
sway_abort("Unknown message type %s", cmdtype);
|
sway_abort("Unknown message type %s", cmdtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(cmdtype);
|
free(cmdtype);
|
||||||
|
|
||||||
if (monitor && type != IPC_SUBSCRIBE) {
|
if (monitor && type != IPC_SUBSCRIBE) {
|
||||||
sway_log(SWAY_ERROR, "Monitor can only be used with -t SUBSCRIBE");
|
if (!quiet) {
|
||||||
|
sway_log(SWAY_ERROR, "Monitor can only be used with -t SUBSCRIBE");
|
||||||
|
}
|
||||||
free(socket_path);
|
free(socket_path);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -454,29 +462,29 @@ int main(int argc, char **argv) {
|
||||||
ipc_set_recv_timeout(socketfd, timeout);
|
ipc_set_recv_timeout(socketfd, timeout);
|
||||||
uint32_t len = strlen(command);
|
uint32_t len = strlen(command);
|
||||||
char *resp = ipc_single_command(socketfd, type, command, &len);
|
char *resp = ipc_single_command(socketfd, type, command, &len);
|
||||||
if (!quiet) {
|
|
||||||
// pretty print the json
|
|
||||||
json_object *obj = json_tokener_parse(resp);
|
|
||||||
|
|
||||||
if (obj == NULL) {
|
// pretty print the json
|
||||||
|
json_object *obj = json_tokener_parse(resp);
|
||||||
|
if (obj == NULL) {
|
||||||
|
if (!quiet) {
|
||||||
fprintf(stderr, "ERROR: Could not parse json response from ipc. "
|
fprintf(stderr, "ERROR: Could not parse json response from ipc. "
|
||||||
"This is a bug in sway.");
|
"This is a bug in sway.");
|
||||||
printf("%s\n", resp);
|
printf("%s\n", resp);
|
||||||
ret = 1;
|
|
||||||
} else {
|
|
||||||
if (!success(obj, true)) {
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
if (type != IPC_SUBSCRIBE || ret != 0) {
|
|
||||||
if (raw) {
|
|
||||||
printf("%s\n", json_object_to_json_string_ext(obj,
|
|
||||||
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
|
|
||||||
} else {
|
|
||||||
pretty_print(type, obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
json_object_put(obj);
|
|
||||||
}
|
}
|
||||||
|
ret = 1;
|
||||||
|
} else {
|
||||||
|
if (!success(obj, true)) {
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) {
|
||||||
|
if (raw) {
|
||||||
|
printf("%s\n", json_object_to_json_string_ext(obj,
|
||||||
|
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
|
||||||
|
} else {
|
||||||
|
pretty_print(type, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json_object_put(obj);
|
||||||
}
|
}
|
||||||
free(command);
|
free(command);
|
||||||
free(resp);
|
free(resp);
|
||||||
|
@ -495,10 +503,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
json_object *obj = json_tokener_parse(reply->payload);
|
json_object *obj = json_tokener_parse(reply->payload);
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
fprintf(stderr, "ERROR: Could not parse json response from ipc"
|
if (!quiet) {
|
||||||
". This is a bug in sway.");
|
fprintf(stderr, "ERROR: Could not parse json response from"
|
||||||
ret = 1;
|
" ipc. This is a bug in sway.");
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
} else if (quiet) {
|
||||||
|
json_object_put(obj);
|
||||||
} else {
|
} else {
|
||||||
if (raw) {
|
if (raw) {
|
||||||
printf("%s\n", json_object_to_json_string(obj));
|
printf("%s\n", json_object_to_json_string(obj));
|
||||||
|
|
Loading…
Reference in a new issue