summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-29 09:04:39 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-29 09:04:39 -0500
commit0af15cc19e4cfa27ff087bb1dc27f71cb4c921cf (patch)
treeed2176af83dca75b5c51d179ace905feb234a024 /sway
parentMerge pull request #272 from mikkeloscar/output-cmd-warnings (diff)
parentFix option parsing (diff)
downloadsway-0af15cc19e4cfa27ff087bb1dc27f71cb4c921cf.tar.gz
sway-0af15cc19e4cfa27ff087bb1dc27f71cb4c921cf.tar.zst
sway-0af15cc19e4cfa27ff087bb1dc27f71cb4c921cf.zip
Merge pull request #269 from christophgysin/usage
Add --help to print usage
Diffstat (limited to 'sway')
-rw-r--r--sway/main.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/sway/main.c b/sway/main.c
index dd609214..1261a7ce 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -55,25 +55,41 @@ int main(int argc, char **argv) {
55 static int verbose = 0, debug = 0, validate = 0; 55 static int verbose = 0, debug = 0, validate = 0;
56 56
57 static struct option long_options[] = { 57 static struct option long_options[] = {
58 {"help", no_argument, NULL, 'h'},
58 {"config", required_argument, NULL, 'c'}, 59 {"config", required_argument, NULL, 'c'},
59 {"validate", no_argument, &validate, 1}, 60 {"validate", no_argument, NULL, 'C'},
60 {"debug", no_argument, &debug, 1}, 61 {"debug", no_argument, NULL, 'd'},
61 {"version", no_argument, NULL, 'v'}, 62 {"version", no_argument, NULL, 'v'},
62 {"verbose", no_argument, &verbose, 1}, 63 {"verbose", no_argument, NULL, 'V'},
63 {"get-socketpath", no_argument, NULL, 'p'}, 64 {"get-socketpath", no_argument, NULL, 'p'},
64 {0, 0, 0, 0} 65 {0, 0, 0, 0}
65 }; 66 };
66 67
67 char *config_path = NULL; 68 char *config_path = NULL;
69
70 const char* usage =
71 "Usage: sway [options] [command]\n"
72 "\n"
73 " -h, --help Show help message and quit.\n"
74 " -c, --config <config> Specify a config file.\n"
75 " -C, --validate Check the validity of the config file, then exit.\n"
76 " -d, --debug Enables full logging, including debug information.\n"
77 " -v, --version Show the version number and quit.\n"
78 " -V, --verbose Enables more verbose logging.\n"
79 " --get-socketpath Gets the IPC socket path and prints it, then exits.\n"
80 "\n";
81
68 int c; 82 int c;
69 while (1) { 83 while (1) {
70 int option_index = 0; 84 int option_index = 0;
71 c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index); 85 c = getopt_long(argc, argv, "hCdvVpc:", long_options, &option_index);
72 if (c == -1) { 86 if (c == -1) {
73 break; 87 break;
74 } 88 }
75 switch (c) { 89 switch (c) {
76 case 0: // Flag 90 case 'h': // help
91 fprintf(stdout, "%s", usage);
92 exit(EXIT_SUCCESS);
77 break; 93 break;
78 case 'c': // config 94 case 'c': // config
79 config_path = strdup(optarg); 95 config_path = strdup(optarg);
@@ -90,7 +106,7 @@ int main(int argc, char **argv) {
90#else 106#else
91 fprintf(stdout, "version not detected\n"); 107 fprintf(stdout, "version not detected\n");
92#endif 108#endif
93 exit(0); 109 exit(EXIT_SUCCESS);
94 break; 110 break;
95 case 'V': // verbose 111 case 'V': // verbose
96 verbose = 1; 112 verbose = 1;
@@ -98,12 +114,15 @@ int main(int argc, char **argv) {
98 case 'p': ; // --get-socketpath 114 case 'p': ; // --get-socketpath
99 if (getenv("SWAYSOCK")) { 115 if (getenv("SWAYSOCK")) {
100 fprintf(stdout, "%s\n", getenv("SWAYSOCK")); 116 fprintf(stdout, "%s\n", getenv("SWAYSOCK"));
101 exit(0); 117 exit(EXIT_SUCCESS);
102 } else { 118 } else {
103 fprintf(stderr, "sway socket not detected.\n"); 119 fprintf(stderr, "sway socket not detected.\n");
104 exit(1); 120 exit(EXIT_FAILURE);
105 } 121 }
106 break; 122 break;
123 default:
124 fprintf(stderr, "%s", usage);
125 exit(EXIT_FAILURE);
107 } 126 }
108 } 127 }
109 128