aboutsummaryrefslogtreecommitdiffstats
path: root/sway/main.c
diff options
context:
space:
mode:
authorLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-26 21:03:21 +0200
committerLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-28 23:50:44 +0200
commit2f2e1f3fc710982fd8577091c344af19ac736d2f (patch)
treea98466a4deb993bbbb85f44f239be600fc4c220b /sway/main.c
parentswaymsg: Print usage and exit on unknown options (diff)
downloadsway-2f2e1f3fc710982fd8577091c344af19ac736d2f.tar.gz
sway-2f2e1f3fc710982fd8577091c344af19ac736d2f.tar.zst
sway-2f2e1f3fc710982fd8577091c344af19ac736d2f.zip
sway: Add --help option that prints usage
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sway/main.c b/sway/main.c
index 7b24d405..473a0990 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -55,6 +55,7 @@ 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, &validate, 1},
60 {"debug", no_argument, &debug, 1}, 61 {"debug", no_argument, &debug, 1},
@@ -69,6 +70,7 @@ int main(int argc, char **argv) {
69 const char* usage = 70 const char* usage =
70 "Usage: sway [options] [command]\n" 71 "Usage: sway [options] [command]\n"
71 "\n" 72 "\n"
73 " -h, --help Show help message and quit.\n"
72 " -c, --config <config> Specify a config file.\n" 74 " -c, --config <config> Specify a config file.\n"
73 " -C, --validate Check the validity of the config file, then exit.\n" 75 " -C, --validate Check the validity of the config file, then exit.\n"
74 " -d, --debug Enables full logging, including debug information.\n" 76 " -d, --debug Enables full logging, including debug information.\n"
@@ -80,13 +82,17 @@ int main(int argc, char **argv) {
80 int c; 82 int c;
81 while (1) { 83 while (1) {
82 int option_index = 0; 84 int option_index = 0;
83 c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index); 85 c = getopt_long(argc, argv, "hCdvVpc:", long_options, &option_index);
84 if (c == -1) { 86 if (c == -1) {
85 break; 87 break;
86 } 88 }
87 switch (c) { 89 switch (c) {
88 case 0: // Flag 90 case 0: // Flag
89 break; 91 break;
92 case 'h': // help
93 fprintf(stdout, "%s", usage);
94 exit(EXIT_SUCCESS);
95 break;
90 case 'c': // config 96 case 'c': // config
91 config_path = strdup(optarg); 97 config_path = strdup(optarg);
92 break; 98 break;