diff options
Diffstat (limited to 'sway/main.c')
-rw-r--r-- | sway/main.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/sway/main.c b/sway/main.c index dd609214..c7696e2e 100644 --- a/sway/main.c +++ b/sway/main.c @@ -55,25 +55,41 @@ int main(int argc, char **argv) { static int verbose = 0, debug = 0, validate = 0; static struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, {"config", required_argument, NULL, 'c'}, - {"validate", no_argument, &validate, 1}, - {"debug", no_argument, &debug, 1}, + {"validate", no_argument, NULL, 'C'}, + {"debug", no_argument, NULL, 'd'}, {"version", no_argument, NULL, 'v'}, - {"verbose", no_argument, &verbose, 1}, + {"verbose", no_argument, NULL, 'V'}, {"get-socketpath", no_argument, NULL, 'p'}, {0, 0, 0, 0} }; char *config_path = NULL; + + const char* usage = + "Usage: sway [options] [command]\n" + "\n" + " -h, --help Show help message and quit.\n" + " -c, --config <config> Specify a config file.\n" + " -C, --validate Check the validity of the config file, then exit.\n" + " -d, --debug Enables full logging, including debug information.\n" + " -v, --version Show the version number and quit.\n" + " -V, --verbose Enables more verbose logging.\n" + " --get-socketpath Gets the IPC socket path and prints it, then exits.\n" + "\n"; + int c; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index); + c = getopt_long(argc, argv, "hCdvVpc:", long_options, &option_index); if (c == -1) { break; } switch (c) { - case 0: // Flag + case 'h': // help + fprintf(stdout, "%s", usage); + exit(EXIT_SUCCESS); break; case 'c': // config config_path = strdup(optarg); @@ -90,7 +106,7 @@ int main(int argc, char **argv) { #else fprintf(stdout, "version not detected\n"); #endif - exit(0); + exit(EXIT_SUCCESS); break; case 'V': // verbose verbose = 1; @@ -98,15 +114,26 @@ int main(int argc, char **argv) { case 'p': ; // --get-socketpath if (getenv("SWAYSOCK")) { fprintf(stdout, "%s\n", getenv("SWAYSOCK")); - exit(0); + exit(EXIT_SUCCESS); } else { fprintf(stderr, "sway socket not detected.\n"); - exit(1); + exit(EXIT_FAILURE); } break; + default: + fprintf(stderr, "%s", usage); + exit(EXIT_FAILURE); } } + // we need to setup logging before wlc_init in case it fails. + if (debug) { + init_log(L_DEBUG); + } else if (verbose || validate) { + init_log(L_INFO); + } else { + init_log(L_ERROR); + } setenv("WLC_DIM", "0", 0); wlc_log_set_handler(wlc_log_handler); detect_nvidia(); @@ -119,14 +146,6 @@ int main(int argc, char **argv) { } register_extensions(); - if (debug) { - init_log(L_DEBUG); - } else if (verbose || validate) { - init_log(L_INFO); - } else { - init_log(L_ERROR); - } - #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); #endif |