aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/worker_main.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-04-29 21:42:33 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-04-29 21:42:33 +0200
commit8b4ad891dce51baa3fb306c617f3368d24600e6d (patch)
tree065cbaee51791d3a35f15547a3c3ff77c97db83a /src/worker_main.c
parentmake struct storage_settings_sqlite opaque (diff)
downloadcimple-8b4ad891dce51baa3fb306c617f3368d24600e6d.tar.gz
cimple-8b4ad891dce51baa3fb306c617f3368d24600e6d.zip
dedupe command line routines
Diffstat (limited to 'src/worker_main.c')
-rw-r--r--src/worker_main.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/worker_main.c b/src/worker_main.c
index 7c78f93..9e9a0b9 100644
--- a/src/worker_main.c
+++ b/src/worker_main.c
@@ -5,13 +5,12 @@
* Distributed under the MIT License.
*/
+#include "cmd_line.h"
#include "const.h"
#include "signal.h"
#include "worker.h"
#include <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
static struct settings default_settings()
{
@@ -19,14 +18,9 @@ static struct settings default_settings()
return settings;
}
-static void print_usage(const char *argv0)
+const char *get_usage_string()
{
- printf("usage: %s [-h|--help] [-V|--version] [-H|--host HOST] [-p|--port PORT]\n", argv0);
-}
-
-static void print_version()
-{
- printf("%s\n", VERSION);
+ return "[-h|--help] [-V|--version] [-H|--host HOST] [-p|--port PORT]";
}
static int parse_settings(struct settings *settings, int argc, char *argv[])
@@ -46,12 +40,10 @@ static int parse_settings(struct settings *settings, int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "hVH:p:", long_options, &longind)) != -1) {
switch (opt) {
case 'h':
- print_usage(argv[0]);
- exit(0);
+ exit_with_usage(0, argv[0]);
break;
case 'V':
- print_version();
- exit(0);
+ exit_with_version();
break;
case 'H':
settings->host = optarg;
@@ -60,8 +52,7 @@ static int parse_settings(struct settings *settings, int argc, char *argv[])
settings->port = optarg;
break;
default:
- print_usage(argv[0]);
- exit(1);
+ exit_with_usage(1, argv[0]);
break;
}
}