Add command line help 70/135470/9
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Thu, 22 Jun 2017 11:08:04 +0000 (13:08 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Tue, 11 Jul 2017 14:56:42 +0000 (16:56 +0200)
Change-Id: I33caa8cd478e7a413ad412a3cf12851944443bb4
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/faultd.c

index 7f72897bc89da6b2aee2af492701dd4c9a956999..b664f60d6e66c45f4de928fa4b480ae6afc70d17 100644 (file)
@@ -49,6 +49,18 @@ int sigint_handler(sd_event_source *s,
        return 0;
 }
 
+static void print_help(const char *name)
+{
+       printf("Usage: %s [OPTIONS]\n"
+                       "Options: \n"
+                       "  --log-level <level>            Set log level to <level>\n"
+                       "  -D                             Set log level to debug\n"
+                       "  -d, --disable-module <module>  Disable <module>\n"
+                       "  --no-action                    Do not execute any action\n"
+                       "  -c, --config-file <file>       Read faultd configuration from <file>\n"
+                       "  -h, --help                     Display this help and exit\n", name);
+}
+
 static int parse_argv(int ac, char *av[])
 {
        int c, r;
@@ -61,6 +73,7 @@ static int parse_argv(int ac, char *av[])
                {"disable-module", required_argument, NULL, 'd'},
                {"no-action", no_argument, NULL, ARG_NO_ACTION},
                {"config-file", required_argument, NULL, 'c'},
+               {"help", no_argument, NULL, 'h'},
                {}
        };
 
@@ -68,7 +81,7 @@ static int parse_argv(int ac, char *av[])
        const char *config_file = FAULTD_DEFAULT_CONFIG_FILE;
        bool using_default_config = 1;
 
-       while ((c = getopt_long(ac, av, "Dc:d:", options, NULL)) >= 0) {
+       while ((c = getopt_long(ac, av, "Dc:d:h", options, NULL)) >= 0) {
                switch (c) {
 
                case ARG_LOG_LEVEL:
@@ -90,6 +103,9 @@ static int parse_argv(int ac, char *av[])
 
                        break;
 
+               case 'h':
+                       print_help(av[0]);
+                       exit(0);
                case 'd':
                        module = faultd_get_module_by_name(optarg);
                        if (module) {
@@ -106,6 +122,7 @@ static int parse_argv(int ac, char *av[])
                        break;
 
                default:
+                       print_help(av[0]);
                        return -EINVAL;
                }
        }