mirror of
https://github.com/swaywm/sway.git
synced 2024-11-21 15:31:28 +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) {
|
||||
socket_path = get_socketpath();
|
||||
if (!socket_path) {
|
||||
if (quiet) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sway_abort("Unable to retrieve socket path");
|
||||
}
|
||||
}
|
||||
|
@ -430,13 +433,18 @@ int main(int argc, char **argv) {
|
|||
} else if (strcasecmp(cmdtype, "subscribe") == 0) {
|
||||
type = IPC_SUBSCRIBE;
|
||||
} else {
|
||||
if (quiet) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sway_abort("Unknown message type %s", cmdtype);
|
||||
}
|
||||
|
||||
free(cmdtype);
|
||||
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
|
@ -454,29 +462,29 @@ int main(int argc, char **argv) {
|
|||
ipc_set_recv_timeout(socketfd, timeout);
|
||||
uint32_t len = strlen(command);
|
||||
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. "
|
||||
"This is a bug in sway.");
|
||||
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(resp);
|
||||
|
@ -495,10 +503,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
json_object *obj = json_tokener_parse(reply->payload);
|
||||
if (obj == NULL) {
|
||||
fprintf(stderr, "ERROR: Could not parse json response from ipc"
|
||||
". This is a bug in sway.");
|
||||
ret = 1;
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "ERROR: Could not parse json response from"
|
||||
" ipc. This is a bug in sway.");
|
||||
ret = 1;
|
||||
}
|
||||
break;
|
||||
} else if (quiet) {
|
||||
json_object_put(obj);
|
||||
} else {
|
||||
if (raw) {
|
||||
printf("%s\n", json_object_to_json_string(obj));
|
||||
|
|
Loading…
Reference in a new issue