summaryrefslogtreecommitdiffstats
path: root/swaymsg/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaymsg/main.c')
-rw-r--r--swaymsg/main.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 3a2e1ee7..f8c9e14c 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -12,7 +12,7 @@
12#include "log.h" 12#include "log.h"
13 13
14void sway_terminate(void) { 14void sway_terminate(void) {
15 exit(1); 15 exit(EXIT_FAILURE);
16} 16}
17 17
18int main(int argc, char **argv) { 18int main(int argc, char **argv) {
@@ -23,22 +23,33 @@ int main(int argc, char **argv) {
23 init_log(L_INFO); 23 init_log(L_INFO);
24 24
25 static struct option long_options[] = { 25 static struct option long_options[] = {
26 {"quiet", no_argument, &quiet, 'q'}, 26 {"help", no_argument, NULL, 'h'},
27 {"quiet", no_argument, NULL, 'q'},
27 {"version", no_argument, NULL, 'v'}, 28 {"version", no_argument, NULL, 'v'},
28 {"socket", required_argument, NULL, 's'}, 29 {"socket", required_argument, NULL, 's'},
29 {"type", required_argument, NULL, 't'}, 30 {"type", required_argument, NULL, 't'},
30 {0, 0, 0, 0} 31 {0, 0, 0, 0}
31 }; 32 };
32 33
34 const char *usage =
35 "Usage: swaymsg [options] [message]\n"
36 "\n"
37 " -h, --help Show help message and quit.\n"
38 " -q, --quiet Be quiet.\n"
39 " -v, --version Show the version number and quit.\n"
40 " -s, --socket <socket> Use the specified socket.\n"
41 " -t, --type <type> Specify the message type.\n";
42
33 int c; 43 int c;
34 while (1) { 44 while (1) {
35 int option_index = 0; 45 int option_index = 0;
36 c = getopt_long(argc, argv, "qvs:t:", long_options, &option_index); 46 c = getopt_long(argc, argv, "hqvs:t:", long_options, &option_index);
37 if (c == -1) { 47 if (c == -1) {
38 break; 48 break;
39 } 49 }
40 switch (c) { 50 switch (c) {
41 case 0: // Flag 51 case 'q': // Quiet
52 quiet = 1;
42 break; 53 break;
43 case 's': // Socket 54 case 's': // Socket
44 socket_path = strdup(optarg); 55 socket_path = strdup(optarg);
@@ -52,8 +63,11 @@ int main(int argc, char **argv) {
52#else 63#else
53 fprintf(stdout, "version not detected\n"); 64 fprintf(stdout, "version not detected\n");
54#endif 65#endif
55 exit(0); 66 exit(EXIT_SUCCESS);
56 break; 67 break;
68 default:
69 fprintf(stderr, "%s", usage);
70 exit(EXIT_FAILURE);
57 } 71 }
58 } 72 }
59 73