sway: Add --help option that prints usage

This commit is contained in:
Christoph Gysin 2015-11-26 21:03:21 +02:00
parent 0d55d1a067
commit 2f2e1f3fc7
2 changed files with 10 additions and 1 deletions

View file

@ -17,6 +17,9 @@ Synopsis
Options Options
------- -------
*-h, --help*::
Show help message and quit.
*-c, \--config* <config>:: *-c, \--config* <config>::
Specifies a config file. Specifies a config file.

View file

@ -55,6 +55,7 @@ int main(int argc, char **argv) {
static int verbose = 0, debug = 0, validate = 0; static int verbose = 0, debug = 0, validate = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"config", required_argument, NULL, 'c'}, {"config", required_argument, NULL, 'c'},
{"validate", no_argument, &validate, 1}, {"validate", no_argument, &validate, 1},
{"debug", no_argument, &debug, 1}, {"debug", no_argument, &debug, 1},
@ -69,6 +70,7 @@ int main(int argc, char **argv) {
const char* usage = const char* usage =
"Usage: sway [options] [command]\n" "Usage: sway [options] [command]\n"
"\n" "\n"
" -h, --help Show help message and quit.\n"
" -c, --config <config> Specify a config file.\n" " -c, --config <config> Specify a config file.\n"
" -C, --validate Check the validity of the config file, then exit.\n" " -C, --validate Check the validity of the config file, then exit.\n"
" -d, --debug Enables full logging, including debug information.\n" " -d, --debug Enables full logging, including debug information.\n"
@ -80,13 +82,17 @@ int main(int argc, char **argv) {
int c; int c;
while (1) { while (1) {
int option_index = 0; 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) { if (c == -1) {
break; break;
} }
switch (c) { switch (c) {
case 0: // Flag case 0: // Flag
break; break;
case 'h': // help
fprintf(stdout, "%s", usage);
exit(EXIT_SUCCESS);
break;
case 'c': // config case 'c': // config
config_path = strdup(optarg); config_path = strdup(optarg);
break; break;